API page: http://api.drupal.org/api/drupal/includes--common.inc/function/drupal_pr...

This information is incomplete/incorrect:

The following states may be applied to an element:

enabled
disabled
visible
invisible
checked
unchecked
expanded
collapsed

The following states may be used in remote conditions:

enabled
disabled
visible
invisible
checked
unchecked
value

It should read:

The following states may be applied to an element:

enabled
disabled
required
optional
visible
invisible
checked
unchecked
expanded
collapsed

The following states may be used in remote conditions:

empty
filled
checked
unchecked
expanded
collapsed
value

For review: "states" are defined as events from line 342 onwards in misc/states.js and "remote conditions" are functions in states.Trigger.states from line 226.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

peterpoe’s picture

peterpoe’s picture

Status: Active » Needs review
jhodgdon’s picture

Title: Documentation problem with drupal_process_states » drupal_process_states - doc listing states is not quite right
Status: Needs review » Needs work

Hm. Could someone please also fix this:

 *
  * The following states exist for both states and remote conditions, but are not
  * fully implemented and may not change anything on the element:

"states exist for both states and..."?!?!? I think it should be "states exist for both elements and..."?

Meanwhile, here is the file referenced above:
http://drupalcode.org/project/drupal.git/blob/HEAD:/misc/states.js
I'm seeing a list of state aliases at line 318, but other than that, how do we verify that this patch is correct -- I don't know a lot about states -- what are the element and remote states?

peterpoe’s picture

Status: Needs work » Needs review
FileSize
1.19 KB

An example (from documentation) should make this clearer:

array(
  'visible' => array(
    ':input[name="remote_checkbox"]' => array('checked' => TRUE),
  ),
)

'visible' is the state that will be applied to the element when the "remote" element (input with name "remote_checkbox") satisfies a "checked == TRUE" condition. That is: the element will be visible only when the input checkbox with name "remote_checkbox" is checked.

The states that can be applied are found here:
http://drupalcode.org/project/drupal.git/blob/HEAD:/misc/states.js#l342

The remote conditions are these:
http://drupalcode.org/project/drupal.git/blob/HEAD:/misc/states.js#l226

Attached is updated patch with rewording suggested in #3.

jhodgdon’s picture

I looked at the code you referenced, and I am not seeing how that matches your patch. For instance, the 2nd link seems to indicate to me that the states for remote are:
empty, checked, value, collapsed
but the list in your patch is quite a bit longer. What am I missing?

peterpoe’s picture

All state and conditions except value have a negative:
filled = !empty
unchecked = !checked
expanded = !collapsed
and so on...

jhodgdon’s picture

OK. That seems reasonable... where is that defined?

And where is that list of "not fully implemented" things coming from?

peterpoe’s picture

They are defined in states.State.aliases:
http://drupalcode.org/project/drupal.git/blob/HEAD:/misc/states.js#l318

The "not fully implemented" states are simply those defined in states.State.aliases that have no corresponding state or condition. Don't ask me why they were left there :)

jhodgdon’s picture

Status: Needs review » Reviewed & tested by the community

OK, I'm convinced. Thanks for helping me understand this. Looks like 7.x/8.x...

Dries’s picture

Status: Reviewed & tested by the community » Fixed

Committed to 7.x and 8.x.

andypost’s picture

Automatically closed -- issue fixed for 2 weeks with no activity.