silverstripe / silverstripe-framework

Silverstripe Framework, the MVC framework that powers Silverstripe CMS
https://www.silverstripe.org
BSD 3-Clause "New" or "Revised" License
721 stars 822 forks source link

[FORMS] Missing Name on CompositeField generates invalid HTML ID #5960

Open tractorcow opened 8 years ago

tractorcow commented 8 years ago

When generating CompositeField instances, invalid HTML id attributes can occur if setName('SomeValidName') is never invoked on it.

FieldGroup gets around this by doing some convoluted string manipulation on child names, but a standard approach is necessary.

This logic should be moved into FormTemplateHelper::generateFieldID(), so that fields without IDs have a reasonable and predictable fallback logic.

@sminnee suggested something along the lines of https://gist.github.com/sminnee/46bbb377d068d012f130f8601f2b856c.

This has an issue where duplicate titles could potentially (yet rarely) generate duplicate IDs, so another alternative is to look at a positional-based solution. In practice it may not be much of an issue however.

This feature is necessary so that CompositeField can be used with the form schema within react, which relies on unique ids.

robbieaverill commented 5 years ago

This feature is necessary so that CompositeField can be used with the form schema within react, which relies on unique ids.

Since #5964 we have composite fields in React form schema - is this still required?

I must say I've found it irritating at times that I can't get a composite field by its name