I'm doing a form with 2 fields to ask a password and to confirm the password.
I would like to have a message on the first field if the pattern is not the good one.
I tried to put attributes in 'options', the pattern goes to 2 fields, but the 'oninvalid' and 'oninput' goes only to the second field.
$textInvalidFormat = $translator->trans('invalidFormat', [], 'general');
$form = $this->createFormBuilder()
->add('password', RepeatedType::class, array(
'type' => PasswordType::class,
'options' => ['attr' => ['oninvalid'=>'setCustomValidity("' .$textInvalidFormat . '")',
'oninput'=>"setCustomValidity('')",
'pattern' => '^(?=.*\d)(?=.*[A-Z])(?=.*[a-z])(?=.*[^\w\d\s:])([^\s]){8,}$']],
'first_options' => array(
'translation_domain' => 'request',
),
'second_options' => array('label' => 'field.request.secondpwd',
'translation_domain' => 'request',),
))
->getForm();
I also tried to put these options in the 'first_options' but the result is the same.
$textInvalidFormat = $translator->trans('invalidFormat', [], 'general');
$form = $this->createFormBuilder()
->add('password', RepeatedType::class, array(
'type' => PasswordType::class,
'first_options' => array(
'translation_domain' => 'request',
'attr' => ['oninvalid'=>'setCustomValidity("' .$textInvalidFormat . '")',
'oninput'=>"setCustomValidity('')",
'pattern' => '^(?=.*\d)(?=.*[A-Z])(?=.*[a-z])(?=.*[^\w\d\s:])([^\s]){8,}$']
),
'second_options' => array('label' => 'field.request.secondpwd',
'translation_domain' => 'request',),
))
->getForm();
The result:
The problem is : I just have the message of my browser but not the one I define in my translation file.
Can you tell me where is the mistake and why the attributes of the 'first_options' doesn't apply ?