1
0
mirror of synced 2024-11-22 05:16:05 +03:00

Merge pull request #5 from 1on/fixes

Fixed shallowEqualObjects on Date and removed field validation on created
This commit is contained in:
Kruglov Kirill 2020-10-16 10:54:49 +03:00 committed by GitHub
commit 2373c1559f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 55 additions and 1 deletions

View File

@ -183,7 +183,9 @@ export default {
this.observeErrors({ callback: this.setErrors, type: 'input', field: this.nameOrFallback })
}
this.updateLocalAttributes(this.$attrs)
if (this.errorBehavior === 'live') {
this.performValidation()
}
},
beforeDestroy () {
if (!this.disableErrors && typeof this.removeErrorObserver === 'function') {

View File

@ -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]

View File

@ -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: `
<FormularioForm v-model="formValues" ref="form">
<FormularioInput v-slot="inputProps" name="testdate" >
<span v-if="inputProps.context.model">{{ inputProps.context.model.getTime() }}</span>
</FormularioInput>
</FormularioForm>
`
})
expect(wrapper.find('span').text()).toBe('123')
wrapper.setData({ formValues: { testdate: new Date(234) } })
await flushPromises()
expect(wrapper.find('span').text()).toBe('234')
})
// ===========================================================================

View File

@ -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: `<div><span v-for="error in props.context.allErrors">{{ error.message }}</span></div>`
}
})
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()