From bbbf0510260399455cd442b2adaea7ba85c3e2ee Mon Sep 17 00:00:00 2001 From: Ulf Gebhardt Date: Tue, 7 May 2019 13:20:50 +0200 Subject: [PATCH] fixed user input event to be fired correctly, added reset event --- .../components/data-input/Form/Form.vue | 42 +++++++++++-------- src/system/components/data-input/Form/demo.md | 8 ++++ 2 files changed, 33 insertions(+), 17 deletions(-) diff --git a/src/system/components/data-input/Form/Form.vue b/src/system/components/data-input/Form/Form.vue index fe84c62..780167e 100755 --- a/src/system/components/data-input/Form/Form.vue +++ b/src/system/components/data-input/Form/Form.vue @@ -1,12 +1,12 @@ @@ -61,13 +61,6 @@ export default { methods: { submit() { this.validate(() => { - /** - * Fires after user input. - * Receives the current form data. - * - * @event input - */ - this.$emit('input', this.newData) /** * Fires on form submit. * Receives the current form data. @@ -81,9 +74,9 @@ export default { const validator = new Schema(this.schema) // Prevent validator from printing to console // eslint-disable-next-line - const warn = console.warn; + const warn = console.warn // eslint-disable-next-line - console.warn = () => {}; + console.warn = () => {} validator.validate(this.newData, errors => { if (errors) { this.errors = errors.reduce((errorObj, error) => { @@ -95,7 +88,7 @@ export default { this.errors = null } // eslint-disable-next-line - console.warn = warn; + console.warn = warn this.notify(this.newData, this.errors) if (!errors && cb && typeof cb === 'function') { cb() @@ -121,10 +114,25 @@ export default { }, async update(model, value) { dotProp.set(this.newData, model, value) - this.validate() + this.validate(() => { + /** + * Fires after user input. + * Receives the current form data. + * + * @event input + */ + this.$emit('input', cloneDeep(this.newData)) + }) }, reset() { - this.$emit('input', cloneDeep(this.value)) + /** + * Fires after reset() was called. + * Receives the current form data. + * Reset has to be handled manually. + * + * @event reset + */ + this.$emit('reset', cloneDeep(this.value)) } }, created() { diff --git a/src/system/components/data-input/Form/demo.md b/src/system/components/data-input/Form/demo.md index 4ca2381..da84f2e 100755 --- a/src/system/components/data-input/Form/demo.md +++ b/src/system/components/data-input/Form/demo.md @@ -51,6 +51,8 @@ Use a schema to provide validation for the form inputs. Use scoped slots to get