3.0 - FormHelper add idPrefix option #2952

markstory opened this Issue Mar 4, 2014 · 3 comments

2 participants

CakePHP member

Currently in 3.0, FormHelper has the chance of generating invalid ID attributes when creating multi-record forms. It also has 0 protection against duplicated ID attributes. Instead of implementing a way to track and increment ID's a more simple solution would be to add an idPrefix option to create():

echo $this->Form->create($article, ['idPrefix' => 'article']);

Then when input() is called the id's would automatically be prefixed with article-. Some additional rules around id prefixing:

  • The prefix would not be applied when the id attribute is defined.
  • ID prefixing would occur in the various places ID's are generated by FormHelper, including radio/multi-checkbox.
@markstory markstory added this to the 3.0.0 milestone Mar 4, 2014
@markstory markstory self-assigned this Mar 8, 2014
CakePHP member

Currently input() and label() use _domId() to generate the ids. Instead shouldn't the FormHelper also use the IdGeneratorTrait by either modifying it's _id() method as required or by simply moving FormHelper::_domId() to IdGeneratorTrait::_domId()?

CakePHP member

That sounds like a reasonable plan. We would also need to make each of the widgets aware of the idPrefix option and have them use it.

@ADmad ADmad referenced this issue Mar 9, 2014

3.0 form idprefix #2980

CakePHP member

Closing, as #2980 has been opened.

@markstory markstory closed this Mar 9, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment