ovld
Version:
ovld unobtrusive client validation for asp.net core mvc
3 lines (2 loc) • 1.85 kB
JavaScript
!function(n){let t={autorun:1};const{find:e,attr:o}=n.core,u="ovldunobs";function r(n,t,e){if(void 0===e)return n.dataset[t];null===e?delete n.dataset[t]:n.dataset[t]=e}function a({selector:t,rules:o,related:a,elements:c,subev:i,msgCont:d}={selector:"form",subev:"submit"}){let f=[];return d=d||function({input:n,name:o}){const u=e(n.closest(t),`[data-valmsg-for="${o}"]`);if(u.length)return u[0]},(c||e(document,t)).forEach((function(t){if(r(t,u))return;r(t,u,1);const e=n.bind({subev:i,cont:t,getRules:()=>l(s(t),o),msgCont:d,related:a});f.push((()=>{e.destroy(),r(t,u,null)}))})),{destroy:()=>{f.forEach((n=>n()))}}}function l(n,t){if(t)for(const e in t)null!=n[e]?n[e]=[...n[e],...t[e]]:n[e]=t[e];return n}function s(t){const u={};function r(n,t){u[n]||(u[n]=[]),u[n].push(t)}var a="data-val-",l=`${a}maxlength`,s=`${a}minlength`,c=l+"-max",i=s+"-min";return e(t,`[${c}]`).forEach((function(t){var e=o(t,c);r(o(t,"name"),{chk:n.rules.maxlen(e),msg:o(t,l)})})),e(t,`[${i}]`).forEach((function(t){var e=o(t,i);r(o(t,"name"),{chk:n.rules.minlen(e),msg:o(t,s)})})),e(t,`[${a}length]`).forEach((function(t){var e=o(t,`${a}length-min`),u=o(t,`${a}length-max`);r(o(t,"name"),{chk:n.rules.len({min:e,max:u}),msg:o(t,`${a}length`)})})),e(t,`[${a}required]`).forEach((function(t){r(o(t,"name"),{chk:n.rules.req,msg:o(t,`${a}required`)})})),u}!function(){document.addEventListener("DOMContentLoaded",(function(){t.autorun&&a()}));const n=window.jQuery;n?n(document).on("ovlduCallBind",(()=>a())):document.addEventListener("ovlduCallBind",(()=>a()));document.dispatchEvent(new CustomEvent("ovlduInit",{cancelable:!0,bubbles:!0,isTrusted:!0}))}(),n.unobtrusive={bind:a,setDefaults:function(n){t=Object.assign({},t,n)},validate:function({cont:t,rules:e}){return n.validate({cont:t,rules:l(s(t),e)})}}}(window.ovld);
//# sourceMappingURL=ovld.unobtrusive.min.js.map