Sha256: 99b526e1ae64adbe344053ae1caa55ef91d4b0cfe92cdf35b0d0956a35b1c43e

Contents?: true

Size: 1.17 KB

Versions: 4

Compression:

Stored size: 1.17 KB

Contents

import{P as i,l as o}from"./lib.js";const a='[class^="pb_"][class*="_kit"]',r=".pb_body_kit_negative",n='form[data-pb-form-validation="true"]',l="input[required],textarea[required],select[required]",d=["change","valid","invalid"];class c extends i{static get selector(){return n}connect(){this.formValidationFields.forEach(e=>{d.forEach(s=>{e.addEventListener(s,o.debounce(t=>{this.validateFormField(t)},250),!1)})})}validateFormField(e){e.preventDefault();const{target:s}=e;s.setCustomValidity(""),e.target.validity.valid?this.clearError(s):this.showValidationMessage(s)}showValidationMessage(e){const{parentElement:s}=e;this.clearError(e),s.closest(a).classList.add("error");const t=this.errorMessageContainer;e.dataset.message&&e.setCustomValidity(e.dataset.message),t.innerHTML=e.validationMessage,s.appendChild(t)}clearError(e){const{parentElement:s}=e;s.closest(a).classList.remove("error");const t=s.querySelector(r);t&&t.remove()}get errorMessageContainer(){const e=document.createElement("div"),s=r.replace(/\./,"");return e.classList.add(s),e}get formValidationFields(){return this._formValidationFields=this._formValidationFields||this.element.querySelectorAll(l)}}window.PbFormValidation=c;

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
playbook_ui-13.32.0.pre.alpha.PLAY14143297 dist/chunks/pb_form_validation.js
playbook_ui-13.32.0.pre.alpha.PLAY14143288 dist/chunks/pb_form_validation.js
playbook_ui-13.32.0.pre.alpha.PLAY14143272 dist/chunks/pb_form_validation.js
playbook_ui-13.32.0.pre.alpha.PLAY14143271 dist/chunks/pb_form_validation.js