You are here

function angularjs_process_select in AngularJS 7

Process ng-select element.

1 string reference to 'angularjs_process_select'
angularjs_element_info in ./angularjs.module
Implements hook_element_info().

File

./angularjs.module, line 365

Code

function angularjs_process_select($element, $form_state) {

  // Pass the option to JS.
  $options = array();
  if (TRUE === isset($element['#options'])) {
    foreach ($element['#options'] as $value => $name) {
      $options[] = array(
        'value' => $value,
        'name' => $name,
      );
    }
  }
  if (TRUE === isset($element['#ng_controller'])) {
    $data['angularjs'][$element['#ng_controller']][$element['#ng_model']] = array(
      'options' => $options,
      'required' => $element['#required'],
      'selected' => $element['#default_value'],
      '_type' => 'select',
      '_name' => $element['#name'],
    );
    $element['#attached']['js'][] = array(
      'type' => 'setting',
      'data' => $data,
    );
  }
  return $element;
}