I created a new control called Webform Structured Text, which is like the date control in that there are child elements of the control the '#value' of which need to be cleared as well as at the control level. That wasn't happening in function _webform_condtional_clear_element_values
, as it assumes a 'flat' structure for all components except for date. A better way to do this would be to call a recursive function to do the clean-up, traversing through all element_children() (and all the 'progeny') of the element, clearing out any '#value' array elements it finds. The recursive function and function _webform_condtional_clear_element_values
would then look like this:
/**
* Helper function to recursively clear out element values.
* @param array $element The element that needs values cleared.
* @return None.
*/
function _webform_conditional_clear_element(&$element) {
if (!isset($element['#type']) || $element['#type'] == 'markup') {
//markup fields don't have user input to clear
//markup is default
return;
}
if (isset($element['#value']) && is_array($element['#value'])) {
foreach ($element['#value'] as $key => $value) {
$element['#value'][$key] = '';
}
}
else {
$element['#value'] = '';
}
foreach ( element_children($element) as $key ) {
_webform_conditional_clear_element($element[$key]);
}
}
/**
* Clear the submitted values for an element
* @param $element
*/
function _webform_condtional_clear_element_values(&$element, &$form_state) {
_webform_conditional_clear_element($element);
// also must clear value in $form_state['values'] so it is not seen by other functions
$reference_element = FALSE;
$reference_set = FALSE;
//loop thru array_parents to find var to reference under "values"
.
.
.
Patch attached. Would be great to get this into the next release. The only other way I thought of doing this would be to provide a hook for components to use to at least allow them to clear out their values themselves.
Shawn
Comment | File | Size | Author |
---|---|---|---|
webform_conditional_XXX_cbd_2014-02-23.patch | 1.94 KB | sdsheridan |