laravel-form-validation
Version:
Yet another form validation helper for Laravel
1 lines • 4.85 kB
JavaScript
!function(t,r){"object"==typeof exports&&"object"==typeof module?module.exports=r(require("axios"),require("object-to-formdata"),require("vue")):"function"==typeof define&&define.amd?define("LaravelForm",["axios","object-to-formdata","vue"],r):"object"==typeof exports?exports.LaravelForm=r(require("axios"),require("object-to-formdata"),require("vue")):t.LaravelForm=r(t.axios,t["object-to-formdata"],t.Vue)}(this,((t,r,e)=>(()=>{"use strict";var o={300:r=>{r.exports=t},614:t=>{t.exports=r},976:t=>{t.exports=e}},n={};function i(t){var r=n[t];if(void 0!==r)return r.exports;var e=n[t]={exports:{}};return o[t](e,e.exports,i),e.exports}i.n=t=>{var r=t&&t.__esModule?()=>t.default:()=>t;return i.d(r,{a:r}),r},i.d=(t,r)=>{for(var e in r)i.o(r,e)&&!i.o(t,e)&&Object.defineProperty(t,e,{enumerable:!0,get:r[e]})},i.o=(t,r)=>Object.prototype.hasOwnProperty.call(t,r),i.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var s={};return(()=>{i.r(s),i.d(s,{Errors:()=>e,FieldErrorComponent:()=>p,Form:()=>c,IsInvalidDirective:()=>d,VueFormPlugin:()=>l,default:()=>c});var t=i(300),r=i.n(t);const e=function(){function t(t){void 0===t&&(t={}),this.errors=t}return t.prototype.all=function(){return this.errors},t.prototype.has=function(t){var r=this.errors.hasOwnProperty(t);return r||(r=Object.keys(this.errors).some((function(r){return r.startsWith("".concat(t,"."))||r.startsWith("".concat(t,"["))}))),r},t.prototype.first=function(t){return this.get(t)[0]},t.prototype.firstWhere=function(t){var r=Object.keys(this.all()).find((function(r){return r.startsWith("".concat(t,"."))||r.startsWith("".concat(t,"["))}));return r?this.first(r):null},t.prototype.get=function(t){return this.errors[t]||[]},t.prototype.any=function(){return Object.keys(this.errors).length>0},t.prototype.flatten=function(){return Object.values(this.errors).reduce((function(t,r){return t.concat(r)}),[])},t.prototype.record=function(t){this.errors=t},t.prototype.clear=function(t){var r={};t&&(r=Object.assign({},this.errors),Object.keys(r).filter((function(r){return r===t||r.startsWith("".concat(t,"."))||r.startsWith("".concat(t,"["))})).map((function(t){return delete r[t]}))),this.record(r)},t}();var o=function(t){if(function(t){return t instanceof Blob||t instanceof FileList}(t))return!0;if("object"==typeof t)for(var r in t)if(t.hasOwnProperty(r)&&o(t[r]))return!0;return!!Array.isArray(t)&&t.some((function(t){return o(t)}))},n=i(614),a=function(){return a=Object.assign||function(t){for(var r,e=1,o=arguments.length;e<o;e++)for(var n in r=arguments[e])Object.prototype.hasOwnProperty.call(r,n)&&(t[n]=r[n]);return t},a.apply(this,arguments)},u=function(){function t(){this.$progress=0,this.$pending=!1,this.$errors=new e}return t.prototype.get=function(t,r){return void 0===r&&(r={}),this.submit("get",t,{},{params:r})},t.prototype.post=function(t,r){return void 0===r&&(r={}),this.submit("post",t,r)},t.prototype.patch=function(t,r){return void 0===r&&(r={}),this.submit("patch",t,r)},t.prototype.put=function(t,r){return void 0===r&&(r={}),this.submit("put",t,r)},t.prototype.delete=function(t,r){return void 0===r&&(r={}),this.submit("delete",t,r)},t.prototype.submit=function(r,e,i,s){var u=this;void 0===i&&(i={}),void 0===s&&(s={});var c=i;return r=r.toLowerCase(),this.$progress=0,this.$errors.clear(),this.$pending=!0,function(t){for(var r in t)if(o(t[r]))return!0;return!1}(c)&&(c=(0,n.serialize)(c,{indices:!0,booleansAsIntegers:!0}),"post"!==r&&(c.append("_method",r),r="post")),new Promise((function(o,n){t.$defaults.axios.request(a(a({url:e,method:r,data:c},u.axiosConfig()),s)).then((function(t){o(t.data)})).catch((function(t){u.onFail(t),n(t)})).then((function(){return u.$pending=!1}))}))},t.prototype.axiosConfig=function(){var t=this;return{onUploadProgress:function(r){t.$progress=Math.round(100*r.loaded/r.total)}}},t.prototype.onFail=function(t){var r;if(422===(null===(r=t.response)||void 0===r?void 0:r.status)){var e=t.response.data;this.$errors.record(e.errors)}},t}();u.$defaults={axios:r()};const c=u;var f=i(976);const p=i.n(f)().extend({name:"FieldError",render:function(t){return this.hasError?t("div",{class:this.className,domProps:{innerText:this.message}}):null},props:{bag:{type:Object,required:!0},field:{type:String,required:!0},className:{type:String,default:"invalid-feedback"}},computed:{hasError:function(){return this.bag.has(this.field)},message:function(){return this.bag.first(this.field)}}}),d=function(t,r){var e=r.value;if(!t.attributes.name)throw new Error("v-invalid directive requires `name` attribute on input.");e.has(t.attributes.name.value)?t.classList.add("is-invalid"):t.classList.remove("is-invalid")};var l={install:function(t){t.directive("invalid",d),t.component("field-error",p)}}})(),s})()));