Adds the ability to reset a form with new resetForm mutation
This commit is contained in:
parent
9448479ada
commit
2ea9ed4134
2
dist/index.js
vendored
2
dist/index.js
vendored
File diff suppressed because one or more lines are too long
@ -76,6 +76,13 @@ export const formulateMutations = (mutations = {}) => Object.assign({
|
|||||||
state.meta = Object.assign({}, state.meta, {
|
state.meta = Object.assign({}, state.meta, {
|
||||||
[form]: Object.assign({}, state.meta[form] || {}, {[field]: data})
|
[form]: Object.assign({}, state.meta[form] || {}, {[field]: data})
|
||||||
})
|
})
|
||||||
|
},
|
||||||
|
resetForm (state, form) {
|
||||||
|
if (state.values[form]) {
|
||||||
|
state.values = Object.assign({}, state.values, {
|
||||||
|
[form]: map(state.values[form], (key, value) => undefined)
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}, mutations)
|
}, mutations)
|
||||||
|
|
||||||
|
@ -164,3 +164,15 @@ test('adds a validationError to existing field', async t => {
|
|||||||
})
|
})
|
||||||
t.deepEqual(state.validationErrors, {form: {name: ['i dislike this field']}})
|
t.deepEqual(state.validationErrors, {form: {name: ['i dislike this field']}})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('reset a form', async t => {
|
||||||
|
let state = {values: {login: {username: 'testuser', password: 'secret'}}}
|
||||||
|
formulateMutations().resetForm(state, 'login')
|
||||||
|
t.deepEqual(state.values, {login: {username: undefined, password: undefined}})
|
||||||
|
})
|
||||||
|
|
||||||
|
test('wont mutate undefined form on reset', async t => {
|
||||||
|
let state = {values: {login: {username: 'testuser', password: 'secret'}}}
|
||||||
|
formulateMutations().resetForm(state, 'register')
|
||||||
|
t.deepEqual(state.values, {login: {username: 'testuser', password: 'secret'}})
|
||||||
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user