You are here

function hook_mathfield_get_token_alter in Math Field 7

Alter the jQuery selector and event for triggering a mathfield.

This hook allows other modules to change the jQuery selector or event for a field type defined in other modules. The source module may be found in $context['field']['module'].

Parameters

array $data: The current token data. An assoicative array with the following keys:

  • 'selector': The jQuery selector for the form element that will tirgger the mathfield evaluation.
  • 'event': The jQuery event that will trigger the mathfield evaluation. Typically, blur of text input and change for select lists and radios/checkboxes.

array $context: An associative array with the following keys:

  • 'field_name': The machine name of the token field.
  • 'delta': The delta value of the token field for multivalue fields. Default is 0.
  • 'column': The source column of the token field. Default is 'value'.
  • 'token': The token used in the math expression.
  • 'field': The field definition of the token field.
  • 'instance': The field instance definition of the token field.
  • 'element': The mathfield form element.
1 invocation of hook_mathfield_get_token_alter()
mathfield_get_tokens in ./mathfield.module
Get the element details for mathfield expression tokens.

File

./mathfield.api.php, line 75
Hooks provided by Math Field.

Code

function hook_mathfield_get_token_alter(&$data, $context) {
  if (empty($data)) {
    $field_name = $context['field']['field_name'];
    $name = strtr('@field_name[@parts]', array(
      '@field_name' => $field_name,
      '@parts' => implode('][', array(
        $context['element']['#language'],
        $context['delta'],
        $context['column'],
      )),
    ));
    $data = array(
      'selector' => 'input[name="' . $name . '"]',
      'event' => 'blur',
    );
  }
}