Commit 95b7ebbd authored by nikunjkotecha's avatar nikunjkotecha Committed by nikunj
Browse files

Issue #3076778 by nikunjkotecha, HeikkiY, naresh_bavaskar: Number field validation not translated

parent 9188dcdb
......@@ -120,6 +120,24 @@ function clientside_validation_jquery_page_attachments(array &$page) {
$config = \Drupal::config('clientside_validation_jquery.settings');
$page['#attached']['drupalSettings']['clientside_validation_jquery']['validate_all_ajax_forms'] = (int) $config->get('validate_all_ajax_forms');
$page['#attached']['drupalSettings']['clientside_validation_jquery']['force_validate_on_blur'] = (bool) $config->get('force_validate_on_blur');
$page['#attached']['drupalSettings']['clientside_validation_jquery']['messages'] = [
'required' => t('This field is required.'),
'remote' => t('Please fix this field.'),
'email' => t('Please enter a valid email address.'),
'url' => t('Please enter a valid URL.'),
'date' => t('Please enter a valid date.'),
'dateISO' => t('Please enter a valid date (ISO).'),
'number' => t('Please enter a valid number.'),
'digits' => t('Please enter only digits.'),
'equalTo' => t('Please enter the same value again.'),
'maxlength' => t('Please enter no more than {0} characters.'),
'minlength' => t('Please enter at least {0} characters.'),
'rangelength' => t('Please enter a value between {0} and {1} characters long.'),
'range' => t('Please enter a value between {0} and {1}.'),
'max' => t('Please enter a value less than or equal to {0}.'),
'min' => t('Please enter a value greater than or equal to {0}.'),
'step' => t('Please enter a multiple of {0}.'),
];
if (empty($page['#cache']['#tags'])) {
$page['#cache']['#tags'] = [];
......
......@@ -5,6 +5,24 @@
(function ($, Drupal, drupalSettings) {
'use strict';
if (typeof drupalSettings.cvJqueryValidateOptions === 'undefined') {
drupalSettings.cvJqueryValidateOptions = {};
}
if (drupalSettings.clientside_validation_jquery.force_validate_on_blur) {
drupalSettings.cvJqueryValidateOptions.onfocusout = function (element) {
// "eager" validation
this.element(element);
};
}
// Add messages with translations from backend.
$.extend($.validator.messages, drupalSettings.clientside_validation_jquery.messages);
// Allow all modules to update the validate options.
// Example of how to do this is shown below.
$(document).trigger('cv-jquery-validate-options-update', drupalSettings.cvJqueryValidateOptions);
/**
* Attaches jQuery validate behavior to forms.
*
......@@ -15,10 +33,6 @@
*/
Drupal.behaviors.cvJqueryValidate = {
attach: function (context) {
if (typeof drupalSettings.cvJqueryValidateOptions === 'undefined') {
drupalSettings.cvJqueryValidateOptions = {};
}
if (typeof Drupal.Ajax !== 'undefined') {
// Update Drupal.Ajax.prototype.beforeSend only once.
if (typeof Drupal.Ajax.prototype.beforeSubmitCVOriginal === 'undefined') {
......@@ -48,18 +62,7 @@
}
}
if (drupalSettings.clientside_validation_jquery.force_validate_on_blur) {
drupalSettings.cvJqueryValidateOptions.onfocusout = function(element) {
// "eager" validation
this.element(element);
};
}
// Allow all modules to update the validate options.
// Example of how to do this is shown below.
$(document).trigger('cv-jquery-validate-options-update', drupalSettings.cvJqueryValidateOptions);
$(context).find('form').each(function() {
$(context).find('form').once('cvJqueryValidate').each(function() {
$(this).validate(drupalSettings.cvJqueryValidateOptions);
});
}
......
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