Hi,
I'm developing a webform component based on the file component that adds support for using a webcam and also cropping the image.
The problem I have is that client side validation isn't triggered as my component isn't called "file" and the code in clientside_validation_webform_after_build_recurse() has a check that the webform component type is "file".
This is the code as is:
if (isset($element['#webform_component']) && $element['#webform_component']['type'] == 'file') {
$file_children = element_children($element);
if (count($file_children) > 0) {
foreach ($file_children as $child) {
$file_child = $element[$child];
if (isset($file_child['#name']) && $file_child['#type'] == 'file') {
$name = $file_child['#name'];
_clientside_validation_set_required($name, $element['#title'], isset($element['#webform_component']['required']) ? (bool)$element['#webform_component']['required'] : FALSE, $js_rules);
if (isset($element['#webform_component']['extra']['filtering']['types'])) {
$extensions = $element['#webform_component']['extra']['filtering']['types'];
_clientside_validation_set_extensions($name, $extensions, $js_rules);
}
}
}
}
}
I need a way to let client side validation know that there is a new webform component that should be treated as a file component.
Obviously I can just patch the code above to include a test for my component e.g.
if (isset($element['#webform_component']) &&
($element['#webform_component']['type'] == 'file' || $element['#webform_component']['type'] == 'MY_FILE_COMPONENT')) {
...
}
But I think it would be better if there was a hook that allowed my module to add it's component to a list of components that should trigger the above code, something like this:
function _clientside_validation_webform_get_file_components() {
$file_components = &drupal_static(__FUNCTION__);
if (empty($file_components)) {
$file_components = array_merge(array('file'), module_invoke_all('clientside_validation_webform_file_components'));
}
return $file_components;
}
Then the original if statement then becomes:
if (isset($element['#webform_component']) && in_array($element['#webform_component']['type'], _clientside_validation_webform_get_file_components())) {
....
}
Then I just need to include the hook in my module like so:
function MYMODULE_clientside_validation_webform_file_components() {
return array('MY_FILE_COMPONENT');
}
I've included a patch of the above changes.
Comment | File | Size | Author |
---|---|---|---|
clientside_validation_support_new_webform_file_components.patch | 1.5 KB | Altcom_Alan | |
Comments