1/** 2 * @file 3 * JavaScript behaviors for webforms. 4 */ 5 6(function ($, Drupal) { 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 $('body') 27 .once('webform-single-submit') 28 .on('submit.singleSubmit', 'form.webform-remove-single-submit', onFormSubmit); 29 } 30 }; 31 32 /** 33 * Prevent webform autosubmit on wizard pages. 34 * 35 * @type {Drupal~behavior} 36 * 37 * @prop {Drupal~behaviorAttach} attach 38 * Attaches the behavior for disabling webform autosubmit. 39 * Wizard pages need to be progressed with the Previous or Next buttons, 40 * not by pressing Enter. 41 */ 42 Drupal.behaviors.webformDisableAutoSubmit = { 43 attach: function (context) { 44 // Not using context so that inputs loaded via Ajax will have autosubmit 45 // disabled. 46 // @see http://stackoverflow.com/questions/11235622/jquery-disable-form-submit-on-enter 47 $('.js-webform-disable-autosubmit input') 48 .not(':button, :submit, :reset, :image, :file') 49 .once('webform-disable-autosubmit') 50 .on('keyup keypress', function (e) { 51 if (e.which === 13) { 52 e.preventDefault(); 53 return false; 54 } 55 }); 56 } 57 }; 58 59 /** 60 * Skip client-side validation when submit button is pressed. 61 * 62 * @type {Drupal~behavior} 63 * 64 * @prop {Drupal~behaviorAttach} attach 65 * Attaches the behavior for the skipping client-side validation. 66 * 67 * @deprecated in Webform 8.x-5.x and will be removed in Webform 8.x-6.x. 68 * Use 'formnovalidate' attribute instead. 69 */ 70 Drupal.behaviors.webformSubmitNoValidate = { 71 attach: function (context) { 72 $(context).find(':submit.js-webform-novalidate') 73 .once('webform-novalidate') 74 .attr('formnovalidate', 'formnovalidate'); 75 } 76 }; 77 78 /** 79 * Custom required and pattern validation error messages. 80 * 81 * @type {Drupal~behavior} 82 * 83 * @prop {Drupal~behaviorAttach} attach 84 * Attaches the behavior for the webform custom required and pattern 85 * validation error messages. 86 * 87 * @see http://stackoverflow.com/questions/5272433/html5-form-required-attribute-set-custom-validation-message 88 **/ 89 Drupal.behaviors.webformRequiredError = { 90 attach: function (context) { 91 $(context).find(':input[data-webform-required-error], :input[data-webform-pattern-error]').once('webform-required-error') 92 .on('invalid', function () { 93 this.setCustomValidity(''); 94 if (this.valid) { 95 return; 96 } 97 98 if (this.validity.patternMismatch && $(this).attr('data-webform-pattern-error')) { 99 this.setCustomValidity($(this).attr('data-webform-pattern-error')); 100 } 101 else if (this.validity.valueMissing && $(this).attr('data-webform-required-error')) { 102 this.setCustomValidity($(this).attr('data-webform-required-error')); 103 } 104 }) 105 .on('input change', function () { 106 // Find all related elements by name and reset custom validity. 107 // This specifically applies to required radios and checkboxes. 108 var name = $(this).attr('name'); 109 $(this.form).find(':input[name="' + name + '"]').each(function () { 110 this.setCustomValidity(''); 111 }); 112 }); 113 } 114 }; 115 116 // When #state:required is triggered we need to reset the target elements 117 // custom validity. 118 $(document).on('state:required', function (e) { 119 $(e.target).filter('[data-webform-required-error]') 120 .each(function () {this.setCustomValidity('');}); 121 }); 122 123})(jQuery, Drupal);
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.