1/** 2 * @file 3 * Attaches behaviors for the Clientside Validation jQuery module. 4 */ 5(function ($, Drupal, once, drupalSettings) { 6 'use strict'; 7 8 if (typeof drupalSettings.cvJqueryValidateOptions === 'undefined') { 9 drupalSettings.cvJqueryValidateOptions = {}; 10 } 11 12 if (drupalSettings.clientside_validation_jquery.force_validate_on_blur) { 13 drupalSettings.cvJqueryValidateOptions.onfocusout = function (element) { 14 // "eager" validation 15 this.element(element); 16 }; 17 } 18 19 // Add messages with translations from backend. 20 $.extend($.validator.messages, drupalSettings.clientside_validation_jquery.messages); 21 22 /** 23 * Attaches jQuery validate behavior to forms. 24 * 25 * @type {Drupal~behavior} 26 * 27 * @prop {Drupal~behaviorAttach} attach 28 * Attaches the outline behavior to the right context. 29 */ 30 Drupal.behaviors.cvJqueryValidate = { 31 attach: function (context) { 32 if (typeof Drupal.Ajax !== 'undefined') { 33 // Update Drupal.Ajax.prototype.beforeSend only once. 34 if (typeof Drupal.Ajax.prototype.beforeSubmitCVOriginal === 'undefined') { 35 var validateAll = 2; 36 try { 37 validateAll = drupalSettings.clientside_validation_jquery.validate_all_ajax_forms; 38 } 39 catch(e) { 40 // Do nothing if we do not have settings or value in settings. 41 } 42 43 Drupal.Ajax.prototype.beforeSubmitCVOriginal = Drupal.Ajax.prototype.beforeSubmit; 44 Drupal.Ajax.prototype.beforeSubmit = function (form_values, element_settings, options) { 45 if (typeof this.$form !== 'undefined' && (validateAll === 1 || $(this.element).hasClass('cv-validate-before-ajax')) && $(this.element).attr("formnovalidate") == undefined) { 46 $(this.$form).removeClass('ajax-submit-prevented'); 47 48 $(this.$form).validate(); 49 if (!($(this.$form).valid())) { 50 this.ajaxing = false; 51 $(this.$form).addClass('ajax-submit-prevented'); 52 return false; 53 } 54 } 55 56 return this.beforeSubmitCVOriginal.apply(this, arguments); 57 }; 58 } 59 } 60 61 // Allow all modules to update the validate options. 62 // Example of how to do this is shown below. 63 $(document).trigger('cv-jquery-validate-options-update', drupalSettings.cvJqueryValidateOptions); 64 65 // Process for all the forms on the page everytime, 66 // we already use once so we should be good. 67 once('cvJqueryValidate', 'body form').forEach(function(element) { 68 $(element).validate(drupalSettings.cvJqueryValidateOptions); 69 }); 70 } 71 }; 72})(jQuery, Drupal, once, drupalSettings);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.