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