1
0
mirror of synced 2024-11-22 13:26:06 +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 })
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) {
// 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
const hasVModelValue = Object.prototype.hasOwnProperty.call(component.$options.propsData, 'formulateValue')
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="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('')
})
// it('does not pre-set internal value of FormulateForm when type "radio" with options', async () => {
// const wrapper = mount({
// data () {
// return {
// radioValue: '',
// formValues: {},
// options: {foo: 'Foo', bar: 'Bar', fooey: 'Fooey'}
// }
// },
// template: `
// <FormulateForm
// v-model="formValues"
// >
// <FormulateInput type="radio" v-model="radioValue" name="foobar" :options="options" />
// </FormulateForm>
// `
// })
// await wrapper.vm.$nextTick()
// await flushPromises()
// expect(wrapper.vm.formValues.foobar).toBe(undefined)
// })
it('does not pre-set internal value of FormulateForm when type "radio" with options', async () => {
const wrapper = mount({
data () {
return {
radioValue: '',
formValues: {},
options: {foo: 'Foo', bar: 'Bar', fooey: 'Fooey'}
}
},
template: `
<FormulateForm
v-model="formValues"
>
<FormulateInput type="radio" v-model="radioValue" name="foobar" :options="options" />
</FormulateForm>
`
})
await wrapper.vm.$nextTick()
await flushPromises()
expect(wrapper.vm.formValues.foobar).toBe('')
})
it('does precheck the correct input when radio with options', async () => {
const wrapper = mount({