Merge pull request #71 from wearebraid/feature/deregister-input
adding FormulateInput deregister functionality
This commit is contained in:
commit
d511c52333
2
dist/formulate.esm.js
vendored
2
dist/formulate.esm.js
vendored
File diff suppressed because one or more lines are too long
2
dist/formulate.min.js
vendored
2
dist/formulate.min.js
vendored
File diff suppressed because one or more lines are too long
2
dist/formulate.umd.js
vendored
2
dist/formulate.umd.js
vendored
File diff suppressed because one or more lines are too long
@ -22,6 +22,7 @@ export default {
|
|||||||
return {
|
return {
|
||||||
formulateFormSetter: this.setFieldValue,
|
formulateFormSetter: this.setFieldValue,
|
||||||
formulateFormRegister: this.register,
|
formulateFormRegister: this.register,
|
||||||
|
formulateFormDeregister: this.deregister,
|
||||||
getFormValues: this.getFormValues,
|
getFormValues: this.getFormValues,
|
||||||
observeErrors: this.addErrorObserver,
|
observeErrors: this.addErrorObserver,
|
||||||
removeErrorObserver: this.removeErrorObserver
|
removeErrorObserver: this.removeErrorObserver
|
||||||
@ -217,6 +218,9 @@ export default {
|
|||||||
this.setFieldValue(field, component.internalModelProxy)
|
this.setFieldValue(field, component.internalModelProxy)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
deregister (field) {
|
||||||
|
delete this.registry[field]
|
||||||
|
},
|
||||||
registerErrorComponent (component) {
|
registerErrorComponent (component) {
|
||||||
if (!this.errorComponents.includes(component)) {
|
if (!this.errorComponents.includes(component)) {
|
||||||
this.errorComponents.push(component)
|
this.errorComponents.push(component)
|
||||||
|
@ -68,6 +68,7 @@ export default {
|
|||||||
inject: {
|
inject: {
|
||||||
formulateFormSetter: { default: undefined },
|
formulateFormSetter: { default: undefined },
|
||||||
formulateFormRegister: { default: undefined },
|
formulateFormRegister: { default: undefined },
|
||||||
|
formulateFormDeregister: { default: undefined },
|
||||||
getFormValues: { default: () => () => ({}) }
|
getFormValues: { default: () => () => ({}) }
|
||||||
},
|
},
|
||||||
model: {
|
model: {
|
||||||
@ -249,6 +250,11 @@ export default {
|
|||||||
this.updateLocalAttributes(this.$attrs)
|
this.updateLocalAttributes(this.$attrs)
|
||||||
this.performValidation()
|
this.performValidation()
|
||||||
},
|
},
|
||||||
|
beforeDestroy () {
|
||||||
|
if (this.formulateFormDeregister && typeof this.formulateFormDeregister === 'function') {
|
||||||
|
this.formulateFormDeregister(this.nameOrFallback)
|
||||||
|
}
|
||||||
|
},
|
||||||
methods: {
|
methods: {
|
||||||
getInitialValue () {
|
getInitialValue () {
|
||||||
// Manually request classification, pre-computed props
|
// Manually request classification, pre-computed props
|
||||||
|
@ -46,6 +46,26 @@ describe('FormulateForm', () => {
|
|||||||
expect(Object.keys(wrapper.vm.registry)).toEqual(['subinput1', 'subinput2'])
|
expect(Object.keys(wrapper.vm.registry)).toEqual(['subinput1', 'subinput2'])
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('deregisters a subcomponents', async () => {
|
||||||
|
const wrapper = mount({
|
||||||
|
data () {
|
||||||
|
return {
|
||||||
|
active: true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
template: `
|
||||||
|
<FormulateForm>
|
||||||
|
<FormulateInput v-if="active" type="text" name="subinput1" />
|
||||||
|
<FormulateInput type="checkbox" name="subinput2" />
|
||||||
|
</FormulateForm>
|
||||||
|
`
|
||||||
|
})
|
||||||
|
expect(Object.keys(wrapper.find(FormulateForm).vm.registry)).toEqual(['subinput1', 'subinput2'])
|
||||||
|
wrapper.setData({ active: false })
|
||||||
|
await flushPromises()
|
||||||
|
expect(Object.keys(wrapper.find(FormulateForm).vm.registry)).toEqual(['subinput2'])
|
||||||
|
})
|
||||||
|
|
||||||
it('can set a field’s initial value', async () => {
|
it('can set a field’s initial value', async () => {
|
||||||
const wrapper = mount(FormulateForm, {
|
const wrapper = mount(FormulateForm, {
|
||||||
propsData: { formulateValue: { testinput: 'has initial value' } },
|
propsData: { formulateValue: { testinput: 'has initial value' } },
|
||||||
|
Loading…
Reference in New Issue
Block a user