Commit a9a0479e authored by Jelle Sebreghts's avatar Jelle Sebreghts
Browse files

Issue #1535756 by pianomansam: Added Support Field Validation 2.x.

parent 16bf0831
......@@ -92,6 +92,17 @@ function clientside_validation_admin_settings() {
'#default_value' => variable_get('clientside_validation_validate_onkeyup', 1),
);
$form['clientside_validation_validate_options']['clientside_validation_show_messages'] = array(
'#type' => 'radios',
'#options' => array(
'0' => t('Show all error messages'),
'1' => t('Show only first error message'),
'2' => t('Show only last error message'),
),
'#title' => t('Show these error messages on validation'),
'#default_value' => variable_get('clientside_validation_show_messages', 0),
);
//Error message settings
$form['clientside_validation_error'] = array(
'#type' => 'fieldset',
......
......@@ -343,6 +343,38 @@
if (!Boolean(parseInt(self.data.general.validateOnKeyUp))) {
validate_options.onkeyup = false;
}
if (parseInt(self.data.general.showMessages) > 0) {
var showMessages = parseInt(self.data.general.showMessages);
// Show only first message
if (showMessages === 1) {
validate_options.showErrors = function() {
for ( var i = 0; this.errorList[i] && i<1; i++ ) {
var error = this.errorList[i];
this.settings.highlight && this.settings.highlight.call( this, error.element, this.settings.errorClass, this.settings.validClass );
this.showLabel( error.element, error.message );
}
if( this.errorList.length ) {
this.toShow = this.toShow.add( this.containers );
}
if (this.settings.success) {
for ( var i = 0; this.successList[i]; i++ ) {
this.showLabel( this.successList[i] );
}
}
if (this.settings.unhighlight) {
for ( var i = 0, elements = this.validElements(); elements[i]; i++ ) {
this.settings.unhighlight.call( this, elements[i], this.settings.errorClass, this.settings.validClass );
}
}
this.toHide = this.toHide.not( this.toShow );
this.hideErrors();
this.addWrapper( this.toShow ).show();
}
}
else if(showMessages === 2) {
}
}
self.validators[f] = $('#' + f).validate(validate_options);
//Disable HTML5 validation
......
......@@ -304,6 +304,7 @@ function _clientside_validation_add_general_settings(&$settings, $form_id) {
"validateOnKeyUp" => variable_get('clientside_validation_validate_onkeyup', 1),
"validateOnSubmit" => variable_get('clientside_validation_validate_onsubmit', 1),
"errorElement" => variable_get('clientside_validation_error_element', 'label'),
"showMessages" => variable_get('clientside_validation_show_messages', 0),
);
}
......
......@@ -100,8 +100,8 @@ function clientside_validation_field_validation_regular($form_id, $element, $rul
// Field Validation 2.x
case 'field_validation_length_validator':
$message = '';
$rule['settings']['min'] = isset($rule['settings']['min']) ? '' : $rule['settings']['min'];
$rule['settings']['max'] = isset($rule['settings']['max']) ? '' : $rule['settings']['max'];
$rule['settings']['min'] = isset($rule['settings']['min']) ? $rule['settings']['min'] : '';
$rule['settings']['max'] = isset($rule['settings']['max']) ? $rule['settings']['max'] : '';
if (isset($rule['error_message'])) {
$message = $rule['error_message'];
}
......@@ -128,8 +128,8 @@ function clientside_validation_field_validation_regular($form_id, $element, $rul
// Field Validation 2.x
case 'field_validation_words_validator':
$message = '';
$rule['settings']['min'] = isset($rule['settings']['min']) ? '' : $rule['settings']['min'];
$rule['settings']['max'] = isset($rule['settings']['max']) ? '' : $rule['settings']['max'];
$rule['settings']['min'] = isset($rule['settings']['min']) ? $rule['settings']['min'] : '';
$rule['settings']['max'] = isset($rule['settings']['max']) ? $rule['settings']['max'] : '';
if (isset($rule['error_message'])) {
$message = $rule['error_message'];
}
......@@ -226,8 +226,8 @@ function clientside_validation_field_validation_regular($form_id, $element, $rul
break;
case 'field_validation_number_of_selections_validator':
$message = '';
$rule['settings']['min'] = isset($rule['settings']['min']) ? '' : $rule['settings']['min'];
$rule['settings']['max'] = isset($rule['settings']['max']) ? '' : $rule['settings']['max'];
$rule['settings']['min'] = isset($rule['settings']['min']) ? $rule['settings']['min'] : '';
$rule['settings']['max'] = isset($rule['settings']['max']) ? $rule['settings']['max'] : '';
if (isset($rule['error_message'])) {
$message = $rule['error_message'];
}
......
Supports Markdown
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