refactor!: FormularioForm - renamed formularioValue into state
This commit is contained in:
parent
fcbe4df667
commit
8144c27c69
@ -36,7 +36,7 @@ type ValidationEventPayload = {
|
||||
@Component({ name: 'FormularioForm' })
|
||||
export default class FormularioForm extends Vue {
|
||||
@Model('input', { default: () => ({}) })
|
||||
public readonly formularioValue!: Record<string, unknown>
|
||||
public readonly state!: Record<string, unknown>
|
||||
|
||||
// Errors record, describing state validation errors of whole form
|
||||
@Prop({ default: () => ({}) }) readonly errors!: Record<string, string[]>
|
||||
@ -52,9 +52,9 @@ export default class FormularioForm extends Vue {
|
||||
private localFieldErrors: Record<string, string[]> = {}
|
||||
|
||||
get initialValues (): Record<string, unknown> {
|
||||
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<string, unknown>): void {
|
||||
@Watch('state', { deep: true })
|
||||
onStateChange (values: Record<string, unknown>): void {
|
||||
if (this.hasModel && values && typeof values === 'object') {
|
||||
this.setValues(values)
|
||||
}
|
||||
|
@ -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: {
|
||||
|
@ -40,7 +40,7 @@ describe('FormularioForm', () => {
|
||||
|
||||
it('Adds subcomponents to the registry', () => {
|
||||
const wrapper = mount(FormularioForm, {
|
||||
propsData: { formularioValue: {} },
|
||||
propsData: { state: {} },
|
||||
slots: {
|
||||
default: `
|
||||
<FormularioField name="sub1" />
|
||||
@ -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: `
|
||||
<FormularioField v-slot="{ context }" validation="required|in:bar" name="test" >
|
||||
@ -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: `
|
||||
<FormularioField v-slot="{ context }" name="test" value="123">
|
||||
@ -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: '<FormularioField name="test" value="Overrides" />'
|
||||
|
Loading…
Reference in New Issue
Block a user