Adds default empty state for non repeatable groups
This commit is contained in:
parent
a08163fba8
commit
9f20c63f13
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
@ -37,7 +37,13 @@ export default {
|
|||||||
inject: ['formulateRegisterRule', 'formulateRemoveRule'],
|
inject: ['formulateRegisterRule', 'formulateRemoveRule'],
|
||||||
computed: {
|
computed: {
|
||||||
items () {
|
items () {
|
||||||
return Array.isArray(this.context.model) ? this.context.model : [{}]
|
if (Array.isArray(this.context.model)) {
|
||||||
|
if (!this.context.repeatable && this.context.model.length === 0) {
|
||||||
|
return [{}]
|
||||||
|
}
|
||||||
|
return this.context.model
|
||||||
|
}
|
||||||
|
return [{}]
|
||||||
},
|
},
|
||||||
providers () {
|
providers () {
|
||||||
return this.items.map((item, i) => Array.isArray(this.$refs[`provider-${i}`]) ? this.$refs[`provider-${i}`][0] : false)
|
return this.items.map((item, i) => Array.isArray(this.$refs[`provider-${i}`]) ? this.$refs[`provider-${i}`][0] : false)
|
||||||
|
@ -5,6 +5,7 @@ import Formulate from '@/Formulate.js'
|
|||||||
import FileUpload from '@/FileUpload.js'
|
import FileUpload from '@/FileUpload.js'
|
||||||
import FormulateInput from '@/FormulateInput.vue'
|
import FormulateInput from '@/FormulateInput.vue'
|
||||||
import FormulateForm from '@/FormulateForm.vue'
|
import FormulateForm from '@/FormulateForm.vue'
|
||||||
|
import FormulateGrouping from '@/FormulateGrouping.vue'
|
||||||
import FormulateRepeatableProvider from '@/FormulateRepeatableProvider.vue'
|
import FormulateRepeatableProvider from '@/FormulateRepeatableProvider.vue'
|
||||||
|
|
||||||
Vue.use(Formulate)
|
Vue.use(Formulate)
|
||||||
@ -396,4 +397,47 @@ describe('FormulateInputGroup', () => {
|
|||||||
expect(repeatables.at(0).text()).toBe('test-0')
|
expect(repeatables.at(0).text()).toBe('test-0')
|
||||||
expect(repeatables.at(1).text()).toBe('test-1')
|
expect(repeatables.at(1).text()).toBe('test-1')
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('forces non-repeatable groups to not initialize with an empty array', async () => {
|
||||||
|
const wrapper = mount({
|
||||||
|
template: `
|
||||||
|
<FormulateInput
|
||||||
|
type="group"
|
||||||
|
name="test"
|
||||||
|
v-model="model"
|
||||||
|
>
|
||||||
|
<div class="repeatable" />
|
||||||
|
</FormulateInput>
|
||||||
|
`,
|
||||||
|
data () {
|
||||||
|
return {
|
||||||
|
model: []
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
await flushPromises();
|
||||||
|
expect(wrapper.find(FormulateGrouping).vm.items).toEqual([{}])
|
||||||
|
})
|
||||||
|
|
||||||
|
it('allows repeatable groups to initialize with an empty array', async () => {
|
||||||
|
const wrapper = mount({
|
||||||
|
template: `
|
||||||
|
<FormulateInput
|
||||||
|
type="group"
|
||||||
|
name="test"
|
||||||
|
:repeatable="true"
|
||||||
|
v-model="model"
|
||||||
|
>
|
||||||
|
<div class="repeatable" />
|
||||||
|
</FormulateInput>
|
||||||
|
`,
|
||||||
|
data () {
|
||||||
|
return {
|
||||||
|
model: []
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
await flushPromises();
|
||||||
|
expect(wrapper.find(FormulateGrouping).vm.items).toEqual([])
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user