|
1 |
| -import { isNil, isBoolean, isEmpty, has, mapValues, union, merge } from 'lodash' |
| 1 | +import { isNil, isBoolean, isEmpty, has, mapValues, union, merge, without, omit } from 'lodash' |
2 | 2 | import { Form, Button } from 'element-ui'
|
3 | 3 | import CONSTANTS from '../../constants'
|
4 | 4 | import { validate, asyncValidate } from '../../validators/validate'
|
@@ -26,6 +26,9 @@ export default {
|
26 | 26 | // Array<String>
|
27 | 27 | formFields: [],
|
28 | 28 |
|
| 29 | + // Array<String> |
| 30 | + removedFields: [], |
| 31 | + |
29 | 32 | // { [fieldName]: true }
|
30 | 33 | touchedFields: {},
|
31 | 34 |
|
@@ -90,6 +93,7 @@ export default {
|
90 | 93 | const vm = this
|
91 | 94 |
|
92 | 95 | this.formFields = union(this.formFields, [name])
|
| 96 | + this.removedFields = without(this.removedFields, name) |
93 | 97 |
|
94 | 98 | const formLevelInitialValue = vm.initialValues[name]
|
95 | 99 | const value = !isNil(formLevelInitialValue) ? formLevelInitialValue : fieldLevelInitialValue
|
@@ -148,6 +152,8 @@ export default {
|
148 | 152 | vm.$delete(this.syncErrors, name)
|
149 | 153 | vm.$delete(this.asyncErrors, name)
|
150 | 154 | vm.$delete(this.touchedFields, name)
|
| 155 | + |
| 156 | + this.removedFields = this.removedFields.concat(name) |
151 | 157 | }
|
152 | 158 |
|
153 | 159 | const setTouched = () => {
|
@@ -231,7 +237,9 @@ export default {
|
231 | 237 |
|
232 | 238 | const off = this.manageSubmittingState()
|
233 | 239 | const submitForm = () =>
|
234 |
| - Promise.resolve(this.handleSubmit(merge({}, this.initialValues, this.state))) |
| 240 | + Promise.resolve( |
| 241 | + this.handleSubmit(merge({}, omit(this.initialValues, this.removedFields), this.state)) |
| 242 | + ) |
235 | 243 |
|
236 | 244 | const submitPromise = this.form.validating
|
237 | 245 | ? Promise.all(Object.values(this.asyncValidations)).then(submitForm)
|
|
0 commit comments