#states element empty check not triggered on mouse based paste

Created on 3 March 2015, almost 10 years ago
Updated 28 February 2023, almost 2 years ago

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.

Feature request
Status

Needs work

Version

10.1

Component
Ajax 

Last updated 1 day ago

Created by

🇺🇸United States DrCord

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024