Skip to content

Commit 42d2264

Browse files
committed
[2.7.3] When form field has removed from form — it value won't be passed to submit
1 parent 181efe8 commit 42d2264

File tree

4 files changed

+18
-3
lines changed

4 files changed

+18
-3
lines changed

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## 2.7.3
2+
3+
### Updated
4+
5+
— When form field has removed from form — it value won't be passed to submit
6+
17
## 2.7.2
28

39
### Fixed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ See demo at [https://detools.github.io/vue-form](https://detools.github.io/vue-f
8080

8181
## Changelog
8282

83+
- [2.7.3](/CHANGELOG.md#273)
8384
- [2.7.2](/CHANGELOG.md#272)
8485
- [2.7.1](/CHANGELOG.md#271)
8586
- [2.7.0](/CHANGELOG.md#270)

VueForm/components/Form/Form.js

+10-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { isNil, isBoolean, isEmpty, has, mapValues, union, merge } from 'lodash'
1+
import { isNil, isBoolean, isEmpty, has, mapValues, union, merge, without, omit } from 'lodash'
22
import { Form, Button } from 'element-ui'
33
import CONSTANTS from '../../constants'
44
import { validate, asyncValidate } from '../../validators/validate'
@@ -26,6 +26,9 @@ export default {
2626
// Array<String>
2727
formFields: [],
2828

29+
// Array<String>
30+
removedFields: [],
31+
2932
// { [fieldName]: true }
3033
touchedFields: {},
3134

@@ -90,6 +93,7 @@ export default {
9093
const vm = this
9194

9295
this.formFields = union(this.formFields, [name])
96+
this.removedFields = without(this.removedFields, name)
9397

9498
const formLevelInitialValue = vm.initialValues[name]
9599
const value = !isNil(formLevelInitialValue) ? formLevelInitialValue : fieldLevelInitialValue
@@ -148,6 +152,8 @@ export default {
148152
vm.$delete(this.syncErrors, name)
149153
vm.$delete(this.asyncErrors, name)
150154
vm.$delete(this.touchedFields, name)
155+
156+
this.removedFields = this.removedFields.concat(name)
151157
}
152158

153159
const setTouched = () => {
@@ -231,7 +237,9 @@ export default {
231237

232238
const off = this.manageSubmittingState()
233239
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+
)
235243

236244
const submitPromise = this.form.validating
237245
? Promise.all(Object.values(this.asyncValidations)).then(submitForm)

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@detools/vue-form",
3-
"version": "2.7.2",
3+
"version": "2.7.3",
44
"description": "Form State Management for VueJS",
55
"main": "VueForm/index.js",
66
"scripts": {

0 commit comments

Comments
 (0)