1
0
mirror of synced 2024-11-25 14:56:03 +03:00

Fixes bug causing FormulateElement's initial prop to occasionally be overwritten by the Formulate initial prop

This commit is contained in:
Justin Schroeder 2018-02-15 23:55:36 -05:00
parent f46a0f66c8
commit fde067d974
3 changed files with 14 additions and 7 deletions

2
dist/index.js vendored

File diff suppressed because one or more lines are too long

View File

@ -47,7 +47,8 @@ export default {
data () { data () {
return { return {
parentIdentifier: 'vue-formulate-wrapper-element', parentIdentifier: 'vue-formulate-wrapper-element',
forceErrors: null forceErrors: null,
fieldInitials: {}
} }
}, },
computed: { computed: {
@ -80,18 +81,21 @@ export default {
return this.showErrors return this.showErrors
} }
return this.behavior === 'live' return this.behavior === 'live'
},
mergedInitial () {
return Object.assign({}, Object.assign({}, this.initial), this.fieldInitials)
} }
}, },
watch: { watch: {
initial () { mergedInitial () {
this.hydrate(this.initial) this.hydrate(this.mergedInitial)
} }
}, },
created () { created () {
this.hydrate(this.initial) this.hydrate(this.mergedInitial)
}, },
mounted () { mounted () {
this.hydrate(this.initial) this.hydrate(this.mergedInitial)
}, },
methods: { methods: {
registerField (field, data) { registerField (field, data) {
@ -110,6 +114,9 @@ export default {
} }
this.updateFormValidation() this.updateFormValidation()
}, },
setInitial (field, value) {
this.fieldInitials[field] = value
},
update (change) { update (change) {
this.$store.commit(`${this.m}setFieldValue`, Object.assign(change, { this.$store.commit(`${this.m}setFieldValue`, Object.assign(change, {
form: this.name form: this.name

View File

@ -294,7 +294,7 @@ export default {
filter(this.$props, (prop, value) => ['name', 'type', 'id', 'label', 'validation', 'validationLabel'].includes(prop)) filter(this.$props, (prop, value) => ['name', 'type', 'id', 'label', 'validation', 'validationLabel'].includes(prop))
) )
if (this.initial !== false) { if (this.initial !== false) {
this.form.hydrate({[this.name]: this.initial}) this.form.setInitial(this.name, this.initial)
} }
} }
} }