diff --git a/src/FormularioForm.vue b/src/FormularioForm.vue index 36ee368..09e421b 100644 --- a/src/FormularioForm.vue +++ b/src/FormularioForm.vue @@ -36,7 +36,7 @@ type ValidationEventPayload = { @Component({ name: 'FormularioForm' }) export default class FormularioForm extends Vue { @Model('input', { default: () => ({}) }) - public readonly formularioValue!: Record + public readonly state!: Record // Errors record, describing state validation errors of whole form @Prop({ default: () => ({}) }) readonly errors!: Record @@ -52,9 +52,9 @@ export default class FormularioForm extends Vue { private localFieldErrors: Record = {} get initialValues (): Record { - if (this.hasModel && typeof this.formularioValue === 'object') { + if (this.hasModel && typeof this.state === 'object') { // If there is a v-model on the form/group, use those values as first priority - return { ...this.formularioValue } // @todo - use a deep clone to detach reference types + return { ...this.state } // @todo - use a deep clone to detach reference types } return {} @@ -69,15 +69,15 @@ export default class FormularioForm extends Vue { } get hasModel (): boolean { - return has(this.$options.propsData || {}, 'formularioValue') + return has(this.$options.propsData || {}, 'state') } get hasInitialValue (): boolean { - return this.formularioValue && typeof this.formularioValue === 'object' + return this.state && typeof this.state === 'object' } - @Watch('formularioValue', { deep: true }) - onFormularioValueChange (values: Record): void { + @Watch('state', { deep: true }) + onStateChange (values: Record): void { if (this.hasModel && values && typeof values === 'object') { this.setValues(values) } diff --git a/test/unit/FormularioFieldGroup.test.js b/test/unit/FormularioFieldGroup.test.js index 7f00156..7f3d0d9 100644 --- a/test/unit/FormularioFieldGroup.test.js +++ b/test/unit/FormularioFieldGroup.test.js @@ -39,7 +39,7 @@ describe('FormularioFieldGroup', () => { it('Grouped fields to be got', async () => { const wrapper = mount(FormularioForm, { propsData: { - formularioValue: { + state: { group: { text: 'Group text' }, text: 'Text', }, @@ -80,7 +80,7 @@ describe('FormularioFieldGroup', () => { it('Errors are set for grouped fields', async () => { const wrapper = mount(FormularioForm, { propsData: { - formularioValue: {}, + state: {}, errors: { 'group.text': 'Test error' }, }, slots: { diff --git a/test/unit/FormularioForm.test.js b/test/unit/FormularioForm.test.js index ecb19d9..94bff26 100644 --- a/test/unit/FormularioForm.test.js +++ b/test/unit/FormularioForm.test.js @@ -40,7 +40,7 @@ describe('FormularioForm', () => { it('Adds subcomponents to the registry', () => { const wrapper = mount(FormularioForm, { - propsData: { formularioValue: {} }, + propsData: { state: {} }, slots: { default: ` @@ -97,7 +97,7 @@ describe('FormularioForm', () => { it('Can set a field’s initial value', async () => { const wrapper = mount(FormularioForm, { - propsData: { formularioValue: { test: 'Has initial value' } }, + propsData: { state: { test: 'Has initial value' } }, slots: { default: ` @@ -112,7 +112,7 @@ describe('FormularioForm', () => { it('Lets individual fields override form initial value', () => { const wrapper = mount(FormularioForm, { - propsData: { formularioValue: { test: 'has initial value' } }, + propsData: { state: { test: 'has initial value' } }, slots: { default: ` @@ -191,7 +191,7 @@ describe('FormularioForm', () => { it('Updates calls setFieldValue on form when a field contains a populated v-model on registration', () => { const wrapper = mount(FormularioForm, { propsData: { - formularioValue: { test: 'Initial' } + state: { test: 'Initial' }, }, slots: { default: ''