Skip to content

Commit

Permalink
Experimentally add j0ber's fix for removeRepeatable events
Browse files Browse the repository at this point in the history
See wearebraid#432 for details. At time
of writing the PR was still open and unapproved.
  • Loading branch information
david-mears-2 committed Mar 2, 2022
1 parent 829ad02 commit 3574d80
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion dist/formulate.esm.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/formulate.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/formulate.umd.js

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions src/FormulateGrouping.vue
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,12 @@ export default {
// In this context we actually have data
this.context.model = this.context.model.filter((item, i) => i === index ? false : item)
this.context.rootEmit('repeatableRemoved', this.context.model)
this.context.rootEmit('repeatable-removed', this.context.model)
} else if (!Array.isArray(this.context.model) && this.items.length > this.context.minimum) {
// In this context the fields have never been touched (not "dirty")
this.context.model = (new Array(this.items.length - 1)).fill('').map((_i, idx) => this.setId({}, idx))
this.context.rootEmit('repeatableRemoved', this.context.model)
this.context.rootEmit('repeatable-removed', this.context.model)
}
// Otherwise, do nothing, we're at our minimum
},
Expand Down
1 change: 1 addition & 0 deletions src/inputs/FormulateInputGroup.vue
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ export default {
this.context.model = (new Array(this.totalItems + 1)).fill('').map(() => setId({}))
}
this.context.rootEmit('repeatableAdded', this.context.model)
this.context.rootEmit('repeatable-added', this.context.model)
},
groupItemContext (context, option, groupAttributes) {
const optionAttributes = { isGrouped: true }
Expand Down
10 changes: 6 additions & 4 deletions test/unit/FormulateInputGroup.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -859,7 +859,8 @@ describe('FormulateInputGroup', () => {
value: [{ username: 'mermaid', email: '[email protected]' }, { username: 'blah', email: '[email protected]' }],
},
listeners: {
'repeatableRemoved': removeListener
'repeatableRemoved': removeListener,
'repeatable-removed': removeListener
},
slots: {
default: `
Expand All @@ -871,7 +872,7 @@ describe('FormulateInputGroup', () => {
await flushPromises()
wrapper.find('.formulate-input-group-repeatable-remove').trigger('click')
await flushPromises()
expect(removeListener.mock.calls.length).toBe(1)
expect(removeListener.mock.calls.length).toBe(2)
})

it('allows passing errors down into groups', async () => {
Expand All @@ -884,7 +885,8 @@ describe('FormulateInputGroup', () => {
value: [{}],
},
listeners: {
'repeatableAdded': addListener
'repeatableAdded': addListener,
'repeatable-added': addListener
},
slots: {
default: `
Expand All @@ -896,7 +898,7 @@ describe('FormulateInputGroup', () => {
await flushPromises()
wrapper.find('.formulate-input-group-add-more button').trigger('click')
await flushPromises()
expect(addListener.mock.calls.length).toBe(1)
expect(addListener.mock.calls.length).toBe(2)
})

it('ensures there are always a minimum number of items even if the model has fewer', async () => {
Expand Down

0 comments on commit 3574d80

Please sign in to comment.