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,KAAL,CAAW,QAAX,EAAqB,CAArB,CAAd;AAAA;AADN;AANW,KAAT,EASL,KAAK,MAAL,CAAY,OATP,CAAR;AAUD;AAhH8C,CAAlC,C","sourcesContent":["// Components\nimport VInput from '../VInput/VInput'\n\n// Mixins\nimport { provide as RegistrableProvide } from '../../mixins/registrable'\n\n// Helpers\nimport { VNode } from 'vue'\n\ntype ErrorBag = Record<number, boolean>\ntype VInputInstance = InstanceType<typeof VInput>\ntype Watchers = {\n _uid: number\n valid: () => void\n shouldValidate: () => void\n}\n\n/* @vue/component */\nexport default RegistrableProvide('form').extend({\n name: 'v-form',\n\n inheritAttrs: false,\n\n props: {\n value: Boolean,\n lazyValidation: Boolean,\n },\n\n data: () => ({\n inputs: [] as VInputInstance[],\n watchers: [] as Watchers[],\n errorBag: {} as ErrorBag,\n }),\n\n watch: {\n errorBag: {\n handler (val) {\n const errors = Object.values(val).includes(true)\n\n this.$emit('input', !errors)\n },\n deep: true,\n immediate: true,\n },\n },\n\n methods: {\n watchInput (input: any): Watchers {\n const watcher = (input: any): (() => void) => {\n return input.$watch('hasError', (val: boolean) => {\n this.$set(this.errorBag, input._uid, val)\n }, { immediate: true })\n }\n\n const watchers: Watchers = {\n _uid: input._uid,\n valid: () => {},\n shouldValidate: () => {},\n }\n\n if (this.lazyValidation) {\n // Only start watching inputs if we need to\n watchers.shouldValidate = input.$watch('shouldValidate', (val: boolean) => {\n if (!val) return\n\n // Only watch if we're not already doing it\n if (this.errorBag.hasOwnProperty(input._uid)) return\n\n watchers.valid = watcher(input)\n })\n } else {\n watchers.valid = watcher(input)\n }\n\n return watchers\n },\n /** @public */\n validate (): boolean {\n return this.inputs.every(input => input.validate(true))\n },\n /** @public */\n reset (): void {\n this.inputs.forEach(input => input.reset())\n this.resetErrorBag()\n },\n resetErrorBag () {\n if (this.lazyValidation) {\n // Account for timeout in validatable\n setTimeout(() => {\n this.errorBag = {}\n }, 0)\n }\n },\n /** @public */\n resetValidation () {\n this.inputs.forEach(input => input.resetValidation())\n this.resetErrorBag()\n },\n register (input: VInputInstance) {\n this.inputs.push(input)\n this.watchers.push(this.watchInput(input))\n },\n unregister (input: VInputInstance) {\n const found = this.inputs.find(i => i._uid === input._uid)\n\n if (!found) return\n\n const unwatch = this.watchers.find(i => i._uid === found._uid)\n if (unwatch) {\n unwatch.valid()\n unwatch.shouldValidate()\n }\n\n this.watchers = this.watchers.filter(i => i._uid !== found._uid)\n this.inputs = this.inputs.filter(i => i._uid !== found._uid)\n this.$delete(this.errorBag, found._uid)\n },\n },\n\n render (h): VNode {\n return h('form', {\n staticClass: 'v-form',\n attrs: {\n novalidate: true,\n ...this.$attrs,\n },\n on: {\n submit: (e: Event) => this.$emit('submit', e),\n },\n }, this.$slots.default)\n },\n})\n"],"sourceRoot":"","file":"VForm.js"} |