function cck_select_other_pre_render in CCK Select Other 7
Same name and namespace in other branches
- 6 cck_select_other.module \cck_select_other_pre_render()
Pre render callback for the form so we can recreate the fake form after it gets blown away by the CCK process callback.
Parameters
$element the element:
$form_state:
Return value
$form
1 string reference to 'cck_select_other_pre_render'
- cck_select_other_element_info in ./
cck_select_other.module - Implementation of hook_element_info().
File
- ./
cck_select_other.module, line 370 - Implements a select list widget that lets a user provide an alternate option.
Code
function cck_select_other_pre_render($element, $form_state = NULL) {
static $js;
$errors = form_get_errors();
if (!empty($errors)) {
// Validation errors for the text input box get lost so need to be injected.
$text_element = $element['#name'] . '[select_other_text_input]';
if (in_array($text_element, array_keys($errors))) {
$element['select_other_text_input']['#attributes']['class'][] = 'error';
}
}
if (!isset($form_state)) {
return $element;
}
if (!isset($element['#type']) || $element['#type'] != 'cck_select_other') {
return $element;
}
// No matches = not our field.
$n = preg_match_all("/[A-Za-z0-9\\-\\_]+/", $element['#name'], $matches);
if ($n == 0) {
return $element;
}
// By any chance if we don't have any array keys, get out of here.
$keys = isset($matches[0]) ? $matches[0] : NULL;
if (!isset($keys)) {
return $element;
}
foreach ($keys as $key => $val) {
$keys[$key] = preg_replace("/_/", '-', $val);
}
$field_id = implode('-', $keys);
if (!$js) {
drupal_add_js(drupal_get_path('module', 'cck_select_other') . '/cck_select_other.js');
$js = TRUE;
}
drupal_add_js(array(
'CCKSelectOther' => array(
array(
'field_id' => $field_id,
),
),
), array(
'type' => 'setting',
));
}