1/** 2 * @file 3 * JavaScript behaviors for webforms. 4 */ 5 6(function ($, Drupal, once) { 7 8 'use strict'; 9 10 /** 11 * Remove single submit event listener. 12 * 13 * @type {Drupal~behavior} 14 * 15 * @prop {Drupal~behaviorAttach} attach 16 * Attaches the behavior for removing single submit event listener. 17 * 18 * @see Drupal.behaviors.formSingleSubmit 19 */ 20 Drupal.behaviors.webformRemoveFormSingleSubmit = { 21 attach: function attach() { 22 function onFormSubmit(e) { 23 var $form = $(e.currentTarget); 24 $form.removeAttr('data-drupal-form-submit-last'); 25 } 26 $(once('webform-single-submit', 'body')) 27 .on('submit.singleSubmit', 'form.webform-remove-single-submit', onFormSubmit); 28 } 29 }; 30 31 /** 32 * Prevent webform autosubmit on wizard pages. 33 * 34 * @type {Drupal~behavior} 35 * 36 * @prop {Drupal~behaviorAttach} attach 37 * Attaches the behavior for disabling webform autosubmit. 38 * Wizard pages need to be progressed with the Previous or Next buttons, 39 * not by pressing Enter. 40 */ 41 Drupal.behaviors.webformDisableAutoSubmit = { 42 attach: function (context) { 43 // Not using context so that inputs loaded via Ajax will have autosubmit 44 // disabled. 45 // @see http://stackoverflow.com/questions/11235622/jquery-disable-form-submit-on-enter 46 $(once('webform-disable-autosubmit', $('.js-webform-disable-autosubmit input').not(':button, :submit, :reset, :image, :file'))) 47 .on('keyup keypress', function (e) { 48 if (e.which === 13) { 49 e.preventDefault(); 50 return false; 51 } 52 }); 53 } 54 }; 55 56 /** 57 * Custom required and pattern validation error messages. 58 * 59 * @type {Drupal~behavior} 60 * 61 * @prop {Drupal~behaviorAttach} attach 62 * Attaches the behavior for the webform custom required and pattern 63 * validation error messages. 64 * 65 * @see http://stackoverflow.com/questions/5272433/html5-form-required-attribute-set-custom-validation-message 66 **/ 67 Drupal.behaviors.webformRequiredError = { 68 attach: function (context) { 69 $(once('webform-required-error', $(context).find(':input[data-webform-required-error], :input[data-webform-pattern-error]'))) 70 .on('invalid', function () { 71 this.setCustomValidity(''); 72 if (this.valid) { 73 return; 74 } 75 76 if (this.validity.patternMismatch && $(this).attr('data-webform-pattern-error')) { 77 this.setCustomValidity($(this).attr('data-webform-pattern-error')); 78 } 79 else if (this.validity.valueMissing && $(this).attr('data-webform-required-error')) { 80 this.setCustomValidity($(this).attr('data-webform-required-error')); 81 } 82 }) 83 .on('input change', function () { 84 // Find all related elements by name and reset custom validity. 85 // This specifically applies to required radios and checkboxes. 86 var name = $(this).attr('name'); 87 $(this.form).find(':input[name="' + name + '"]').each(function () { 88 this.setCustomValidity(''); 89 }); 90 }); 91 } 92 }; 93 94 // When #state:required is triggered we need to reset the target elements 95 // custom validity. 96 $(document).on('state:required', function (e) { 97 $(e.target).filter(':input[data-webform-required-error]') 98 .each(function () {this.setCustomValidity('');}); 99 }); 100 101})(jQuery, Drupal, once);
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.