diff --git a/src/FormularioInput.vue b/src/FormularioInput.vue index 2df8c4d..d36649f 100644 --- a/src/FormularioInput.vue +++ b/src/FormularioInput.vue @@ -183,7 +183,9 @@ export default { this.observeErrors({ callback: this.setErrors, type: 'input', field: this.nameOrFallback }) } this.updateLocalAttributes(this.$attrs) - this.performValidation() + if (this.errorBehavior === 'live') { + this.performValidation() + } }, beforeDestroy () { if (!this.disableErrors && typeof this.removeErrorObserver === 'function') { diff --git a/src/libs/utils.js b/src/libs/utils.js index 09a596d..124c22b 100644 --- a/src/libs/utils.js +++ b/src/libs/utils.js @@ -33,6 +33,14 @@ export function shallowEqualObjects (objA, objB) { return false } + if (objA instanceof Date && objB instanceof Date) { + return objA.getTime() === objB.getTime(); + } + + if (len === 0) { + return objA === objB; + } + for (var i = 0; i < len; i++) { var key = aKeys[i] diff --git a/test/unit/FormularioForm.test.js b/test/unit/FormularioForm.test.js index 01d2644..1f6d980 100644 --- a/test/unit/FormularioForm.test.js +++ b/test/unit/FormularioForm.test.js @@ -136,6 +136,31 @@ describe('FormularioForm', () => { expect(wrapper.vm.formValues).toEqual({ testinput: 'edited value' }) }) + it('field data updates when it is type of date', async () => { + const wrapper = mount({ + data () { + return { + formValues: { + testdate: new Date(123), + } + } + }, + template: ` + + + {{ inputProps.context.model.getTime() }} + + + ` + }) + expect(wrapper.find('span').text()).toBe('123') + + wrapper.setData({ formValues: { testdate: new Date(234) } }) + await flushPromises() + + expect(wrapper.find('span').text()).toBe('234') + }) + // =========================================================================== diff --git a/test/unit/FormularioInput.test.js b/test/unit/FormularioInput.test.js index 0903401..a9676de 100644 --- a/test/unit/FormularioInput.test.js +++ b/test/unit/FormularioInput.test.js @@ -44,6 +44,22 @@ describe('FormularioInput', () => { expect(wrapper.find('span').text()).toBe('the value was different than expected') }) + it('no validation on created when errorBehavior is not live', async () => { + const wrapper = mount(FormularioInput, { + propsData: { + name: 'test', + validation: 'required|in:abcdef', + validationMessages: {in: 'the value was different than expected'}, + value: 'other value' + }, + scopedSlots: { + default: `
{{ error.message }}
` + } + }) + await flushPromises() + expect(wrapper.find('span').exists()).toBe(false) + }) + it('allows custom field-rule level validation functions', async () => { const wrapper = mount(FormularioInput, { propsData: { @@ -268,6 +284,9 @@ describe('FormularioInput', () => { ` } }) + await flushPromises() + expect(wrapper.find('span').exists()).toBe(false) + wrapper.trigger('submit') await flushPromises()