You are here

function mathfield_widget_ajax in Math Field 7

Ajax callback: Returns the updated mathfield element.

1 string reference to 'mathfield_widget_ajax'
mathfield_field_widget_form in ./mathfield.module
Implements hook_field_widget_form().

File

./mathfield.module, line 404
Adds a dynamic math expression field.

Code

function mathfield_widget_ajax($form, $form_state) {
  $trigger = $form_state['triggering_element'];

  // Remove the final column portion of the parents array to update the
  // entire trigger element.
  $parents = $trigger['#parents'];
  array_splice($parents, -1, 1);
  $element = drupal_array_get_nested_value($form, $parents);

  // Build the ajax response.
  $response = array(
    '#type' => 'ajax',
    '#commands' => ajax_prepare_response($element),
  );
  $response['#commands'][] = array(
    'command' => 'mathfieldUpdate',
  );
  return $response;
}