Skip to content

Commit 73e1e8b

Browse files
Fixes a bug that caused box inputs to reset their value when hydrated from a form and nested inside groups
1 parent 3b41e16 commit 73e1e8b

File tree

7 files changed

+36
-10
lines changed

7 files changed

+36
-10
lines changed

dist/formulate.esm.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/formulate.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/formulate.umd.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/specimens/SpecimenGroup.vue

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,26 @@
1919
/>
2020
</FormulateInput>
2121
</div>
22+
<div class="specimen">
23+
<h3>Simple repeatable group</h3>
24+
{{ formData }}
25+
<FormulateForm
26+
v-model="formData"
27+
>
28+
<FormulateInput
29+
type="group"
30+
name="foobar"
31+
:repeatable="true"
32+
>
33+
<div class="wrap">
34+
<FormulateInput
35+
type="text"
36+
name="name"
37+
/>
38+
</div>
39+
</FormulateInput>
40+
</FormulateForm>
41+
</div>
2242
<div class="specimen">
2343
<h3>Repeatable group</h3>
2444
<FormulateInput
@@ -54,5 +74,10 @@
5474

5575
<script>
5676
export default {
77+
data () {
78+
return {
79+
formData: {}
80+
}
81+
}
5782
}
5883
</script>

src/FormulateGrouping.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ export default {
110110
},
111111
setItem (index, groupProxy) {
112112
// Note: value must have an __id to use this function
113-
if (Array.isArray(this.context.model) && this.context.model.length >= this.context.minimum) {
113+
if (Array.isArray(this.context.model) && this.context.model.length >= this.context.minimum && !this.context.model.__init) {
114114
this.context.model.splice(index, 1, this.setId(groupProxy, index))
115115
} else {
116116
this.context.model = this.items.map((item, i) => i === index ? this.setId(groupProxy, index) : item)

src/FormulateInput.vue

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,9 @@ export default {
424424
return this.value
425425
} else if (has(this.$options.propsData, 'formulateValue')) {
426426
return this.formulateValue
427+
} else if (classification === 'group') {
428+
// Set the value of an empty group
429+
return Object.defineProperty(this.type === 'group' ? [{}] : [], '__init', { value: true })
427430
}
428431
return ''
429432
},

test/unit/FormulateInputGroup.test.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -713,7 +713,7 @@ describe('FormulateInputGroup', () => {
713713
})
714714
})
715715

716-
// This is basically the same test as found in FormulateForm sicne they share registry logic.
716+
// This is basically the same test as found in FormulateForm since they share registry logic.
717717
it('can swap input types with the same name without loosing registration, but resetting values', async () => {
718718
const wrapper = mount({
719719
template: `
@@ -739,7 +739,7 @@ describe('FormulateInputGroup', () => {
739739
}
740740
})
741741
await flushPromises()
742-
wrapper.find('input').setValue('Justin')
742+
wrapper.find('input[name="test"]').setValue('Justin')
743743
await flushPromises()
744744
expect(wrapper.vm.formData).toEqual({ country: 'it', languages: [{ test: 'Justin' }] })
745745
wrapper.setData({ lang: 'en' })
@@ -1059,7 +1059,7 @@ describe('FormulateInputGroup', () => {
10591059
).toEqual(['@fb-jane'])
10601060
})
10611061

1062-
it.only('does not let checkboxes wipe their own value out', async () => {
1062+
it('does not let checkboxes wipe their own value out', async () => {
10631063
const wrapper = mount({
10641064
template: `
10651065
<FormulateForm
@@ -1089,9 +1089,7 @@ describe('FormulateInputGroup', () => {
10891089
})
10901090
await flushPromises()
10911091
expect(wrapper.vm.formData).toEqual({
1092-
pizzas: [{
1093-
flavors: ['pepperoni', 'pineapple']
1094-
}]
1092+
pizzas: [{ flavors: ['pepperoni', 'pineapple'] }]
10951093
})
10961094
})
10971095
})

0 commit comments

Comments
 (0)