1
0
mirror of synced 2024-11-26 07:16:02 +03:00
This commit is contained in:
Justin Schroeder 2020-03-02 01:34:18 -05:00
parent c6eae3493b
commit 192a2cd93b
6 changed files with 47 additions and 26 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -108,7 +108,17 @@ export default {
Object.assign(this.internalFormModelProxy, { [field]: value }) Object.assign(this.internalFormModelProxy, { [field]: value })
this.$emit('input', Object.assign({}, this.internalFormModelProxy)) this.$emit('input', Object.assign({}, this.internalFormModelProxy))
}, },
getUniqueRegistryName (base, count = 0) {
if (Object.prototype.hasOwnProperty.call(this.registry, base + (count || ''))) {
return this.getUniqueRegistryName(base, count + 1)
}
return base + (count || '')
},
register (field, component) { register (field, component) {
// Don't re-register fields... @todo come up with another way of handling this that doesn't break multi option
if (Object.prototype.hasOwnProperty.call(this.registry, field)) {
return false
}
this.registry[field] = component this.registry[field] = component
const hasVModelValue = Object.prototype.hasOwnProperty.call(component.$options.propsData, 'formulateValue') const hasVModelValue = Object.prototype.hasOwnProperty.call(component.$options.propsData, 'formulateValue')
const hasValue = Object.prototype.hasOwnProperty.call(component.$options.propsData, 'value') const hasValue = Object.prototype.hasOwnProperty.call(component.$options.propsData, 'value')

View File

@ -210,4 +210,15 @@ describe('FormulateForm', () => {
expect(wrapper.find('input[type="text"]').element.value).toBe('Dave Barnett') expect(wrapper.find('input[type="text"]').element.value).toBe('Dave Barnett')
expect(wrapper.find('input[type="checkbox"]').element.checked).toBe(true) expect(wrapper.find('input[type="checkbox"]').element.checked).toBe(true)
}) })
it('shows error messages when it includes a checkbox with options', async () => {
const wrapper = mount(FormulateForm, {
propsData: { formulateValue: { box3: [] } },
slots: { default: '<FormulateInput type="checkbox" name="box3" validation="required" :options="{first: \'First\', second: \'Second\', third: \'Third\'}" />' }
})
wrapper.trigger('submit')
await wrapper.vm.$nextTick()
await flushPromises()
expect(wrapper.find('.formulate-input-error').exists()).toBe(true)
})
}) })

View File

@ -140,27 +140,27 @@ describe('FormulateInputBox', () => {
expect(wrapper.vm.radioValue).toBe('') expect(wrapper.vm.radioValue).toBe('')
}) })
// it('does not pre-set internal value of FormulateForm when type "radio" with options', async () => { it('does not pre-set internal value of FormulateForm when type "radio" with options', async () => {
// const wrapper = mount({ const wrapper = mount({
// data () { data () {
// return { return {
// radioValue: '', radioValue: '',
// formValues: {}, formValues: {},
// options: {foo: 'Foo', bar: 'Bar', fooey: 'Fooey'} options: {foo: 'Foo', bar: 'Bar', fooey: 'Fooey'}
// } }
// }, },
// template: ` template: `
// <FormulateForm <FormulateForm
// v-model="formValues" v-model="formValues"
// > >
// <FormulateInput type="radio" v-model="radioValue" name="foobar" :options="options" /> <FormulateInput type="radio" v-model="radioValue" name="foobar" :options="options" />
// </FormulateForm> </FormulateForm>
// ` `
// }) })
// await wrapper.vm.$nextTick() await wrapper.vm.$nextTick()
// await flushPromises() await flushPromises()
// expect(wrapper.vm.formValues.foobar).toBe(undefined) expect(wrapper.vm.formValues.foobar).toBe('')
// }) })
it('does precheck the correct input when radio with options', async () => { it('does precheck the correct input when radio with options', async () => {
const wrapper = mount({ const wrapper = mount({