You are here

function conditional_fields_field_selector in Conditional Fields 4.x

Same name and namespace in other branches
  1. 8 conditional_fields.module \conditional_fields_field_selector()
  2. 7.3 conditional_fields.module \conditional_fields_field_selector()

Builds a jQuery selector from the name or id attribute of a field.

@todo support custom selectors with %lang and %key placeholders.

Parameters

array $field: The field form element.

Return value

string|FALSE A jQuery selector string.

3 calls to conditional_fields_field_selector()
ConditionalFieldsFormHelper::buildJquerySelectorForField in src/ConditionalFieldsFormHelper.php
Build a jQuery selector for a field, from its name or ID attribute.
DateList::statesHandler in src/Plugin/conditional_fields/handler/DateList.php
Executes states handler according to conditional fields settings.
OptionsButtons::checkBoxesHandler in src/Plugin/conditional_fields/handler/OptionsButtons.php
Return state for check boxes.

File

./conditional_fields.module, line 309
Contains conditional_fields.module.

Code

function conditional_fields_field_selector($field) {
  if (isset($field['#attributes']['name'])) {
    return '[name="' . $field['#attributes']['name'] . '"]';
  }
  if (isset($field['#name'])) {
    return '[name="' . $field['#name'] . '"]';
  }

  // Try with id if name is not found.
  if (isset($field['#attributes']['id'])) {
    return '#' . $field['#attributes']['id'];
  }
  if (isset($field['#id'])) {
    return '#' . $field['#id'];
  }
  return FALSE;
}