PageSourceSearch

https://www.opera-bordeaux.com/modules/contrib/clientside_validati…/js/cv.jquery.validate.js?tm8bkb

js opera-bordeaux.com collected 2026-10-02 04:06:08 UTC 3,679 bytes, 96 lines download raw bytes

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    var rules = [];
10    $("input[type=time]").each(function () {
11      var field_name = $(this).attr("name");
12      rules[field_name] = {'step': false};
13    });
14    drupalSettings.cvJqueryValidateOptions = {
15      rules: rules
16    };
17  }
18
19  if (drupalSettings.clientside_validation_jquery.force_validate_on_blur) {
20    drupalSettings.cvJqueryValidateOptions.onfocusout = function (element) {
21      // "eager" validation
22      this.element(element);
23    };
24  }
25
26  // Add messages with translations from backend.
27  $.extend($.validator.messages, drupalSettings.clientside_validation_jquery.messages);
28
29  // Overwrite default URL validation method, accepting public/private urlscheme.
30  var _urlValidation = $.validator.methods.url;
31  $.validator.methods.url = function(value, element) {
32    return _urlValidation.call(this, value, element) || /^(public|private):\/\//.test(value);
33  }
34
35  /**
36   * Attaches jQuery validate behavior to forms.
37   *
38   * @type {Drupal~behavior}
39   *
40   * @prop {Drupal~behaviorAttach} attach
41   *  Attaches the outline behavior to the right context.
42   */
43  Drupal.behaviors.cvJqueryValidate = {
44    attach: function (context) {
45      if (typeof Drupal.Ajax !== 'undefined') {
46        // Update Drupal.Ajax.prototype.beforeSend only once.
47        if (typeof Drupal.Ajax.prototype.beforeSubmitCVOriginal === 'undefined') {
48          var validateAll = 2;
49          try {
50            validateAll = drupalSettings.clientside_validation_jquery.validate_all_ajax_forms;
51          }
52          catch(e) {
53            // Do nothing if we do not have settings or value in settings.
54          }
55
56          Drupal.Ajax.prototype.beforeSubmitCVOriginal = Drupal.Ajax.prototype.beforeSubmit;
57          Drupal.Ajax.prototype.beforeSubmit = function (form_values, element_settings, options) {
58            if (typeof this.$form !== 'undefined' && (validateAll === 1 || $(this.element).hasClass('cv-validate-before-ajax')) && $(this.element).attr("formnovalidate") == undefined) {
59              $(this.$form).removeClass('ajax-submit-prevented');
60
61              // Handle for the HTML5 validation if enabled.
62              var forceHtml5Validation = drupalSettings.clientside_validation_jquery.force_html5_validation;
63              var formId = $(this.$form).attr('id');
64              if (forceHtml5Validation && formId) {
65                if (!document.getElementById(formId).reportValidity()) {
66                  this.ajaxing = false;
67                  $(this.$form).addClass('ajax-submit-prevented');
68                  return false;
69                }
70              }
71
72              $(this.$form).validate();
73              if (!($(this.$form).valid())) {
74                this.ajaxing = false;
75                $(this.$form).addClass('ajax-submit-prevented');
76                return false;
77              }
78            }
79
80            return this.beforeSubmitCVOriginal.apply(this, arguments);
81          };
82        }
83      }
84
85      // Allow all modules to update the validate options.
86      // Example of how to do this is shown below.
87      $(document).trigger('cv-jquery-validate-options-update', drupalSettings.cvJqueryValidateOptions);
88
89      // Process for all the forms on the page everytime,
90      // we already use once so we should be good.
91      once('cvJqueryValidate', 'body form').forEach(function(element) {
92        $(element).validate(drupalSettings.cvJqueryValidateOptions);
93      });
94    }
95  };
96})(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.