To change attribute values of form elements I'm using a javascript that accesses them thanks to their name attribute.
The form component of Symfony2.2 is generating an automatic name value made of the return value of getName() function and the name given to the element in the BuidlForm method.
public function getName()
{
return 'UserAccountCreateAccount';
}
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('firstName', 'text',
In this example my name attribute will have the value UserAccountCreateAccount[firstName]
When I try this in java:
useraccountinfoform.UserAccountCreateAccount[firstName].readOnly = true;
java is certainly misinterpreting (array I guess) and not working.
The only workaround I found is to return an empty string in getName() to have "firstName" as a name for the attribute.
public function getName()
{
return '';
}
In the javascript:
useraccountinfoform.firstName.readOnly = true;
is then working.
Is there another and cleaner way to handle this and have a name attribute value generated by Symfony that can be understood by the javascript?
Note: I tried this :
$builder
->add('firstName', 'text',
array('attr' => array('name' => 'firstName')));
but this is not working since I got 2 name attributes for the same element and the first one only is considered by java (that is "UserAccountCreateAccount[firstName]")