function _hierarchical_select_mark_as_disabled in Hierarchical Select 7.3
Same name and namespace in other branches
- 5.3 hierarchical_select.module \_hierarchical_select_mark_as_disabled()
- 6.3 hierarchical_select.module \_hierarchical_select_mark_as_disabled()
Helper function that marks every element in the given element as disabled.
Parameters
&$element: The element of which we want to mark all elements as disabled.
Return value
A structured array for use in the Forms API.
1 call to _hierarchical_select_mark_as_disabled()
- form_hierarchical_select_process in ./
hierarchical_select.module - Hierarchical select form element type #process callback.
File
- ./
hierarchical_select.module, line 1512 - This module defines the "hierarchical_select" form element, which is a greatly enhanced way for letting the user select items in a hierarchy.
Code
function _hierarchical_select_mark_as_disabled(&$element) {
// Setting $element['#disabled'] = TRUE resulted in undesired side-effects:
// when the dropbox limit would be reached after pressing the "Add" button,
// then the *entire form* would be submitted. Using #attributes instead does
// not trigger this behavior.
// Based on documentation of @see _form_builder_handle_input_element():
// "If a form wants to start a control off with one of these attributes
// for UI purposes only, but still allow input to be processed if it's
// sumitted, it can set the desired attribute in #attributes directly
// rather than using #disabled."
// #disabled prevents #value from containing values for disabled elements,
// but using #attributes circumvents this. Most likely, Form API thinks that
// because HS' selects are disabled, that the whole of HS is disabled (which
// is of course a wrong assumption). Hence it thinks the 'op' that is being
// passed ('Add') is wrong and is forcefully being set through JS (which is
// also a wrong assumption). Hence it reverts to the main form's default
// submit handler.
$element['#attributes']['disabled'] = TRUE;
// Recurse through all children:
foreach (element_children($element) as $key) {
if (isset($element[$key]) && $element[$key]) {
_hierarchical_select_mark_as_disabled($element[$key]);
}
}
}