Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Confirmation Message for FormHelper doesn't support newline characters #17449

Open
Manuel1948 opened this issue Nov 24, 2023 · 2 comments
Open
Milestone

Comments

@Manuel1948
Copy link
Contributor

Manuel1948 commented Nov 24, 2023

Description

In CakePHP 3 the kind of the confirmation message implementation supported newline charcters.

Now in CakePHP 4 it is not possible anymore to integrate newline characters or I simply don't know how.

In CakePHP 3 the following code:

<?= $this->Form->postLink(
    'Delete',
    ['action' => 'delete', $article->id],
    ['confirm' => 'Text in the first line.\nSome text in the next line'])
?>

generated a JS dialog which supported newlines in the confirmation dialog, because the generated HTML was like:

<a href="#" onclick="if (confirm(&quot;Text in the first line.\nSome text in the next line&quot;)) { document.post_6560f918b6034460798220.submit(); } event.returnValue = false; return false;">Delete</a>

but now there will be generated the following piece of code:

<a href="#" data-confirm-message="Text in the first line.\nSome text in the next line" onclick="if (confirm(this.dataset.confirmMessage)) { document.post_6560f91ecb213856330014.submit(); } event.returnValue = false; return false;">Delete</a>

So what is the correct way to implement newlines in the messages or does the cakephp code has to be edited?

My current workaround is to replace all \n ind my confirmation messages with &#10;

CakePHP Version

4.5.1

PHP Version

8.2

@markstory markstory added this to the 4.5.2 milestone Nov 24, 2023
@markstory markstory added the view label Nov 24, 2023
@LordSimal
Copy link
Contributor

I personally have an overwritten FormHelper to adjust that postLink behavior with Sweetalert since its a much nicer modal than the default browser one.

If we can fix this new line behavior bug in Cake I am fine with putting that in, but in the end I would recommend everyone who needs more functionality from what the default Helpers provide to overwrite or even write their own Helpers to get exactly what they need.

@markstory markstory modified the milestones: 4.5.2, 4.5.3 Dec 15, 2023
@markstory markstory modified the milestones: 4.5.3, 4.5.4 Jan 20, 2024
@markstory markstory modified the milestones: 4.5.4, 4.5.5 Mar 6, 2024
@dereuromark
Copy link
Member

For me those worked afaik, if those are actual newline characters, using " instead of ' in PHP.
But otherwise I would recommend using spaces for your case, or str_replace() those into spaces at runtime.

@markstory markstory modified the milestones: 4.5.5, 4.5.6 May 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants