Quantcast
Channel:
Viewing all articles
Browse latest Browse all 4235

Giving a HiddenField (or any other field) a custom id attribute

$
0
0

SS 2.4.5

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)


Posted to: Giving a HiddenField (or any other field) a custom id attribute | Show Thread | Post Reply


Viewing all articles
Browse latest Browse all 4235

Trending Articles