You are here

function conditional_fields_field_selector in Conditional Fields 8

Same name and namespace in other branches
  1. 7.3 conditional_fields.module \conditional_fields_field_selector()
  2. 4.x 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.

4 calls to conditional_fields_field_selector()
ConditionalFieldsFormHelper::getSelector in src/ConditionalFieldsFormHelper.php
Build a jQuery selector if it was not overridden by a custom value.
ConditionalFieldsFormHelper::processDependeeFields in src/ConditionalFieldsFormHelper.php
Determine and register dependee field effects.
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 310
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;
}