-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
Set default idPrefix for Form Helper #6134
Comments
I agree that we should be closer to the uniqueness 2.x provided to avoid unnecessary collisions, which seem to be quite likely with just the flat data array and thus the field names directly. It might also make sense to further prefix it with something that shows that those ids are not part of the layouting structure, but form data related. Together with @DSchalla s idea it could be:
or something like that. The branding/word "cake" I would try to keep out of it, though :) |
Yeah I like the idea, something like that would make sense imho. Maybe instead of data use form to make clears its related to an form of this entity, but sounds great otherwise. |
If you know you will have collisions, why not just set the idPrefix. The helper will not always be able to guess the prefix which is why it doesn't try. |
Set the ID Prefix for every form instead of just setting an default prefix which makes it much more unlikely overcomplicates things, don't you think so? Sure, I could add a form prefix in about 30 forms, but that seems way more complicated than adding just a default prefix which avoids that trouble for multiple people, since I cannot see a disadvantage of that Enhancement at all. The helper cannot guess the prefix, of course, but it can have an default prefix which avoids generic ids like title, id, content, created to be existent twice in an system. There is not any drawback, since the prefix can still be overwritten in the helper call. |
Is the problem that you are getting collisions between forms, or between inputs and layout elements? |
Well, HTML ids have to be unique, and when I got an div#content and an entity property content, this leads to the collision. So basically between input and layout elements, but it could be anything else. |
You can also get collisions when using forms loaded via ajax in a popup for example. I solved this uniqueness problem by setting the id prefix to "Text::uuid()" in Form->create(). |
I would rather have a more basic prefix like "data" again, as it was in 2.x. Everyone else can still make it more unique if he needs to. The current collisions (by default), though, are not a good thing to keep either way. |
There was no generic id prefix in 2.0 @dereuromark. I think @jabd's pull request is headed in the right direction though. |
@markstory The model name was that prefix afaik. |
Since the default idPrefix for the FormHelper is "null", this can lead to id collisions on a website.
As example:
I got an DB with the columns id, username, title, content, so the FormHelper creates all inputs by default with:
<label for="content">...<//label><textarea name="content" id="content"></textarea>
Since content is a common id for the content wrapper etc and those collisions might come up also with other ids, I would say it makes sense to set the default idPrefix for the FormHelper to "cakeForm" to reach relative unique ids like "cakeForm-title", "cakeForm-content" etc to avoid collisions at all.
The ID Prefix above was just an example, you get the idea.
The text was updated successfully, but these errors were encountered: