Class: Dependent

Drupal.states. Dependent

new Drupal.states.Dependent(args)

Object representing an element that depends on other elements.

Name Type Description
args object

Object with the following keys (all of which are required)

Name Type Description
element jQuery

A jQuery object of the dependent element

state Drupal.states.State

A State object describing the state that is dependent

constraints object

An object with dependency specifications. Lists all elements that this element depends on. It can be nested and can contain arbitrary AND and OR clauses.

Members

staticDrupal.states.Dependent.comparisons

Comparison functions for comparing the value of an element with the specification from the dependency settings. If the object type can't be found in this list, the === operator is used by default.

Properties:
Name Type Description
RegExp function
Function function
Number function

Methods

checkConstraints(value, selector, state){bool}

Checks whether the value matches the requirements for this constraint.

Name Type Description
value string | Array | object

Either the value of a state or an array/object of constraints. In the latter case, resolving the constraint continues.

selector string optional

The selector for this constraint. If undefined, there isn't yet a selector that this constraint applies to. In that case, the state key is propagates to a selector and resolving continues.

state Drupal.states.State optional

The state to check for this constraint. If undefined, resolving continues. If both selector and state aren't undefined and valid non-numeric strings, a lookup for the actual value of that selector's state is performed. This parameter is not a State object but a pristine state string.

Returns:
Type Description
bool true or false, depending on whether this constraint is satisfied.

compare(reference, selector, state){bool}

Compares a value with a reference value.

Name Type Description
reference object

The value used for reference.

selector string

CSS selector describing the dependee.

state Drupal.states.State

A State object describing the dependee's updated state.

Returns:
Type Description
bool true or false.

getDependees(){object}

Gathers information about all required triggers.

Returns:
Type Description
object An object describing the required triggers.

initializeDependee(selector, dependeeStates)

Initializes one of the elements this dependent depends on.

Name Type Description
selector string

The CSS selector describing the dependee.

dependeeStates object

The list of states that have to be monitored for tracking the dependee's compliance status.

reevaluate()

Triggers change events in case a state changed.

update(selector, state, value)

Update the value of a dependee's state.

Name Type Description
selector string

CSS selector describing the dependee.

state Drupal.states.state

A State object describing the dependee's updated state.

value string

The new value for the dependee's updated state.

verifyConstraints(constraints, selector){bool}

Evaluates child constraints to determine if a constraint is satisfied.

Name Type Description
constraints object | Array

A constraint object or an array of constraints.

selector string

The selector for these constraints. If undefined, there isn't yet a selector that these constraints apply to. In that case, the keys of the object are interpreted as the selector if encountered.

Returns:
Type Description
bool true or false, depending on whether these constraints are satisfied.