function autocomplete_widgets_validate in Autocomplete Widgets for Text and Number Fields 6
Validate a textfield autocomplete element.
1 string reference to 'autocomplete_widgets_validate'
- autocomplete_widgets_process in ./
autocomplete_widgets.module - Process an individual textfield autocomplete element.
File
- ./
autocomplete_widgets.module, line 165 - Provides autocomplete widgets for CCK Text and Number fields.
Code
function autocomplete_widgets_validate($element, &$form_state) {
$field_name = $element['#field_name'];
$type_name = $element['#type_name'];
$delta = $element['#delta'];
$field = content_fields($field_name, $type_name);
$field_key = $element['#columns'][0];
$value = trim($element['#value']);
if ($field['widget']['type'] == 'autocomplete_widgets_allowvals') {
if ($value !== '') {
module_load_include('inc', 'autocomplete_widgets', 'autocomplete_widgets.common');
$options = _autocomplete_widgets_get_options($field, $value, 'equals', NULL, 1);
if (empty($options)) {
form_error($element, t('%name: found no valid option.', array(
'%name' => $field['widget']['label'],
)));
}
else {
$value = key($options);
}
}
}
// Remove the wrapper layer and set the right element's value.
// This will move the nested value at 'field-name-0-value-value'
// back to its original location, 'field-name-0-value'.
form_set_value($element, $value, $form_state);
}