Early Bird Registration for DrupalCon Portland 2024 is open! Register by 23:59 PST on 31 March 2024, to get $100 off your ticket.
Because Clientside validation States tries to validate every type of HTLM element forms often break.
Only input, select and textaread should be validated after a state change.
With the Drupal States API you can also change other HTML elements, so we need to take care of those.
Next to that, there is a problem during validation if the target is not visible. So this should be accounted for as well.
This can happen if for example the 'required' state is defined before 'visible'.
Example errors:
Uncaught TypeError: Cannot read property 'element' of undefined
at HTMLDivElement.<anonymous> (jquery.validate.js?oxe870:103)
at Function.each (jquery.min.js?v=1.10.2:3)
at $.fn.init.each (jquery.min.js?v=1.10.2:3)
at $.fn.init.valid (jquery.validate.js?oxe870:102)
at HTMLDocument.<anonymous> (clientside_validation_states.js?oxe870:31)
at HTMLDocument.dispatch (jquery.min.js?v=1.10.2:4)
at HTMLDocument.v.handle (jquery.min.js?v=1.10.2:4)
at Object.trigger (jquery.min.js?v=1.10.2:4)
at HTMLDivElement.<anonymous> (jquery.min.js?v=1.10.2:4)
at Function.each (jquery.min.js?v=1.10.2:3)
Example form:
$form['show'] = array(
'#type' => 'select',
'#title' => t('Show radios'),
'#options' => array(
'no' => t('No'),
'yes' => t('Yes'),
),
);
$form['radios'] = array(
'#type' => 'select',
'#title' => t('Radios'),
'#options' => array(
'option1' => t('Option'),
'option2' => t('Option'),
),
'#states' => array(
'required' => array(
':input[name="show"]' => array('value' => 'yes'),
),
'visible' => array(
':input[name="show"]' => array('value' => 'yes'),
),
);
);
Comment | File | Size | Author |
---|---|---|---|
#2 | clientside_validation_states_radios-2914383-2.patch | 910 bytes | sjerdo |
Comments
Comment #2
sjerdoI have attached a patch for this issue.
This patch will only validate fields that are visible.
Also it will find the form elements within the states target and validate these, instead of the wrapper around the radios.
Comment #3
sjerdoComment #4
dmsmidtClarify IS.
Comment #5
dmsmidtWorks like a charm
Comment #7
nikunjkotecha