If you have a dependent element #states set as such:
'disabled' => array(
':input[name="dependee-field"]' => array('filled' => TRUE)
)
and you right click into the dependee-field and select paste from the contextual menu, the dependee-field is filled with the value but the dependent field(s) are not disabled.
Looking at the file: <drupal root>/misc/states.js
starting on line 365:
empty: {
// 'keyup' is the (native DOM) event that we watch for.
'keyup': function () {
// The function associated to that trigger returns the new value for the
// state.
return this.val() == '';
}
},
It is clear that the empty check that is used for the keyword "filled" only triggers on the "keyup" event, not mouse actions.
I was able to make a change that works, but is a little weird UI wise.
empty: {
// 'keyup' is the (native DOM) event that we watch for.
'keyup': function () {
// The function associated to that trigger returns the new value for the
// state.
return this.val() == '';
},
'change': function(){
return this.val() == '';
}
},
This causes the dependent field to be disabled normally when the keyboard is used to enter data into the dependee field. It also causes the dependent field to be disabled on right-click paste, but only once the user clicks out of the field, this is not quite ideal, but does get the intended job done. I am happy to make a patch, but wanted to make sure the slight UI weirdness is acceptable before bothering.
Comment | File | Size | Author |
---|---|---|---|
#23 | reroll_diff_11-23.txt | 1.12 KB | sahil.goyal |
#23 | 2445271-23.patch | 336 bytes | sahil.goyal |
#11 | states_element_empty-2445271-11.patch | 868 bytes | pguillard |
#9 | states_element_empty-2445271-9-d7.patch | 456 bytes | SpadXIII |
#8 | states_element_empty-2445271-8.patch | 919 bytes | jrockowitz |
Comments
Comment #1
DrCord CreditAttribution: DrCord commentedComment #2
dcam CreditAttribution: dcam commentedThis section of states.js is the same in Drupal 8. It would have to be changed there first, then backported.
Comment #5
scotwith1tSame thing here, but it's not just mouse-based pasting. Using a tool like JumpCut to paste also doesn't trigger the 'filled' criteria being set to TRUE, so dependent form components don't get displayed when something is pasted into the field.
Comment #8
jrockowitz CreditAttribution: jrockowitz as a volunteer and at The Big Blue House commentedWe just ran into this issue in the Webform module. @see #2911822: Enable list options (buttons) if the precedent list options is filled
Attached is a patch based on the suggested tweak. I don't have ES6 setup locally but the patch should work.
Marking as 'Needs review' to trigger the automated test but this patch definitely needs work.
Comment #9
SpadXIII CreditAttribution: SpadXIII at ezCompany commentedI've added a Drupal 7 patch as I just ran into this issue as well with a date field which uses a date popup.
Comment #11
pguillard CreditAttribution: pguillard commentedJust a patch reroll fr 8.6.x
Comment #13
pguillard CreditAttribution: pguillard commentedComment #23
sahil.goyal CreditAttribution: sahil.goyal as a volunteer and at Srijan | A Material+ Company for Drupal India Association commentedReroll the #11 and attaching reroll_diff along.
Comment #24
Prem Suthar CreditAttribution: Prem Suthar at Srijan | A Material+ Company for Drupal India Association commentedAs per #11 Patch failed to apply because in 10.1x dev this issue is no more present So we can Close the Issue.