PageSourceSearch

https://www.rimi.ee/epood/front/js/chunks/validator.CrL_srjA.js

js rimi.ee collected 2026-09-24 20:06:20 UTC 4,564 bytes, 1 lines download raw bytes

1import{$ as s}from"./jquery.CKSFNtpw.js";import{d as T}from"./utils.C0Wtsi1I.js";const h="validator.init",l="validator.validate",f="validator.errors.show",v="validator.errors.set",u="validator.errors.clear",m="validator.validated",p="validator.success",O="validator.load",E="validator.submit",_="submit",B="validate",d="validator-is-bound",c="form.validatable",L=c+"[data-"+d+"=true]",R=c+":not([data-"+d+"])",g=c+".no-submit";class o{form;response_data;method;action;errors;clickedButton;constructor(t){typeof t=="string"&&(t=s(t)),!t.is(L)&&(this.form=t,this.markBound(),this.listen(),this.trigger(h,null))}listen(){this.on(h,()=>this.init()),this.on(l,(t,r)=>this.validate(t,r)),this.on(u,()=>this.clearErrors()),this.on(v,(t,r)=>this.setErrors(r)),this.on(f,()=>this.showErrors()),this.on(p,()=>this.success()),this.on(`${_} ${B}`,t=>this.trigger(l,t)),s(this.form[0]).on(_,t=>{this.trigger(E,[t])}),this.form.is(g)&&this.on(E,t=>t.preventDefault()),this.errorFieldListener()}errorFieldListener(){const t=this.form;this.form.on("keyup",".form-field.-has-error :input",function(){o.removeErrors(s(this).parents(".form-field"),t)}),this.form.on("change",'.form-field.-has-error :input[type="radio"]',function(){o.removeErrors(s(this).parents(".form-field"),t)})}markBound(){this.form.attr("data-"+d,"true")}on(t,r){this.form.on(t,r)}trigger(t,r){this.form.trigger(t,r)}init(){const t=this.form;this.errors=[],this.response_data={},this.method=t.attr("method")||"get",this.action=t.attr("action")}validate=(t,r)=>{r.preventDefault(),r&&r.preventDefault(),this.setClickedButton();const e=this.fetch();this.trigger(u,null),e.then(i=>{this.errors=null,this.trigger(m,i),this.response_data=i,this.trigger(p,i)}).catch(i=>{this.errors=i.responseJSON?i.responseJSON.errors:!1,this.errors||(this.errors={message:[i.responseJSON.message]}),this.trigger(m,i.responseJSON),this.form.find(".loading").trigger("loadingend"),this.trigger(f,null)})};fetch(){const t={url:this.action,type:this.method,data:null,headers:{Accept:"application/json"},contentType:!1,processData:!1};if(this.method.toLowerCase()==="post"){const e=new FormData(this.form[0]);e.append("is_validation_request","true"),this.clickedButton&&e.append(this.clickedButton.attr("name"),this.clickedButton.attr("value")),t.data=e}else{const e=this.form.serialize();t.url=`${t.url}?is_validation_request=true&${e}`,this.clickedButton&&(t.url+="&"+[this.clickedButton.attr("name"),this.clickedButton.attr("value")].join("="))}return s.ajax(t).done(e=>e)}setClickedButton(){const t=s(document.activeElement);t.is("button[name]")&&this.form.find(t)?this.clickedButton=t:this.clickedButton=null}clearErrors(){return o.removeErrors(this.form.find(".form-field"),this.form)}setErrors(t){this.errors=t}showErrors(){const t=this.errors,r=[];for(const e in t){const i=this.getFieldFromKey(e),n=t[e][0];if(i){o.appendErrorToField(n,i);continue}r.push(n)}if(r.length){this.appendErrorsToNotification(r);return}s(".-has-error:first").trigger("scrollintoview")}getFieldFromKey(t){const r=T(t),e=this.form.find(`input[name="${r}"], textarea[name="${r}"], select[name="${r}"]`).not('[type="hidden"]');if(e.length===1)return e;const i=this.form.find(`input[name="${r}"][type="radio"]`).not('[type="hidden"]');return i.length>0?s(i[0]):null}appendErrorsToNotification(t){let r=this.form.find(".validation-errors");r.length===0&&(r=s('<div class="validation-errors"/>'),this.form.prepend(r)),r.addClass("show");for(const i in t)r.append(s("<p/>").text(t[i]));s(this.form.find(".validation-errors")[0]).trigger("scrollintoview")}static appendErrorToField(t,r){r.parents(".form-field").addClass("-has-error"),r.parents(".form-field").append(o.makeErrorMessage(t))}static removeErrors(t,r){t.each(function(e,i){const n=s(i);n.removeClass("-has-error"),n.find(".form-field__error-msg").remove()}),r.find(".validation-errors").each(function(e,i){s(i).empty()})}success(){this.response_data?.redirect?globalThis.location.href=this.response_data.redirect:this.form.is(g)||(this.clickedButton&&this.insertClickedButtonInput(),this.form[0].submit())}insertClickedButtonInput(){const t=s('<input type="hidden"/>');t.attr("name",this.clickedButton.attr("name")).val(this.clickedButton.attr("value")),this.form.append(t),this.clickedButton.removeAttr("name")}static makeErrorMessage(t){return s('<span class="form-field__error-msg">').text(t)}}const A=s("body");A.on("contentloaded",function(a){s(a.target).find(R).each((r,e)=>{new o(s(e))})});A.on(O,function(a){new o(s(a.target))});
1export{f as V,p as a,l as b,v as c,o as d,h as e,u as f};

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.