Commit 252a5d29 authored by jelles's avatar jelles
Browse files

webform min date

parent fabe2333
......@@ -8,10 +8,10 @@
* Implements hook_clientside_validation_form_alter().
*/
function clientside_validation_form_clientside_validation_form_alter(&$form, &$form_state, &$js_rules) {
clientside_validation_form_after_build_recurse($form['#id'], $form, $form_state, $js_rules);
_clientside_validation_form_after_build_recurse($form['#id'], $form, $form_state, $js_rules);
}
function clientside_validation_form_after_build_recurse($form_id, &$form, &$form_state, &$js_rules) {
function _clientside_validation_form_after_build_recurse($form_id, &$form, &$form_state, &$js_rules) {
if ($children = array_values(element_children($form))) {
foreach ($children as $index => $item) {
$element = &$form[$item];
......
<?php
class CvWebformDateMinValidator extends CvWebformValidator {
public function supports(array $element, array &$form_state) {
if (!parent::supports($element, $form_state)) {
return FALSE;
}
return (
$element['#webform_component']['type'] == 'date'
&& (isset($element['#year_start']) || isset($element['#start_date']))
);
}
public function getJavascriptSettings(array $element, array &$form_state) {
$element_name = isset($element['#year_start']) ? $this->getName($element) . '[year]' : 'webform-component-' . str_replace('_', '-', implode('--', array_slice($element['#parents'], 1)));
$rule_name = isset($element['#year_start']) ? 'min' : 'datemin';
$settings = array(
'rules' => array(
$element_name => array(
$rule_name => isset($element['#year_start']) ? $element['#year_start'] : explode('-', $element['#end_date']),
),
),
'messages' => array(
$element_name => array(
$rule_name => isset($element['#year_start']) ? 'The year in the entered date must be before !year' : 'The entered date must be before !date',
),
),
);
return $settings;
}
}
<?php
$plugin = array(
'label' => t('Date'),
'validator' => array(
'class' => 'CvWebformDateMinValidator',
),
);
......@@ -5,7 +5,7 @@ Core
[x]decimalpoint
[x]integer
[x]maxlength
[x ]minlength
[x]minlength
[x]max
[x]min
[x]required
......@@ -13,8 +13,7 @@ Core
Webform
-------
[x]date (required)
[ ]date (format)
[ ]date (min)
[x]date (min)
[ ]date (max)
[x]decimalcomma
[x]decimalpoint
......@@ -38,3 +37,8 @@ Webform Validation
FAPI Validation
---------------
Other
-----
[ ]date (format)
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment