22972 Posts in 11596 Topics by 2824 members
|Go to End|
20 September 2013 at 2:18pm Last edited: 20 September 2013 2:32pm
Pretty simple question, but I don't see anything in the docs: http://api.silverstripe.org/2.4/class-HiddenField.html
I am creating a form for a frontend page. This page also has some custom JS that does some funky stuff to the form based on field id's. So I want full control over the id of any field, in this particular case, a hidden field.
The only work around I have found is to use LiteralField and give it an HTML field:
new LiteralField('Name', '<input id="thisIsMyId" name="Name" type="hidden" />');
Is this the only way? Or is there an argument/method I am missing with HiddenField, TextField etc to change the id attribute of the generated field?
P.S. We have a custom validation model for this form. So I can't think of a reason why the form would need Silverstripe's default generated id. (FormName_FieldName)
20 September 2013 at 6:17pm
If you want full control over the ID you're a bit outta luck for 3.* - https://github.com/silverstripe/silverstripe-framework/blob/3.1/forms/FormField.php#L164. You could create a Subclass of FormField and override the ID method as normal inheritance. I've made this customisable in 3.2 (master / unreleased) along with other improvements to the Form ID generation - https://github.com/silverstripe/silverstripe-framework/commit/ca87b8b79496a78454d63c225f1f4f38fa55a150
26 September 2013 at 9:59pm
Cheers Will, yeah I saw that when I dove into the code.
Sticking with the LiteralField in this case.
|Go to Top|