Skip to content

Commit

Permalink
added option resetOthers for fromJson()
Browse files Browse the repository at this point in the history
  • Loading branch information
brainfoolong committed Sep 27, 2021
1 parent 5505afc commit 4a01101
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
### 2.0.3beta - 27.09.2021
* fixed https://github.com/brainfoolong/form-data-json/issues/13 in `toJson()`
* option `uncheckedValue` is now false by default, instead of undefined
* changed option `uncheckedValue` is now false by default, instead of undefined
* added option `resetOthers` for `fromJson()`

### 2.0.2beta - 27.09.2021
* incorrectly compiled files
Expand Down
11 changes: 11 additions & 0 deletions src/form-data-json.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,13 @@ class FormDataJson {
*/
'clearOthers': false,

/**
* If true, than all fields that are not exist in the passed values object, will be reset
* Not exist means, the value must be undefined
* @type {boolean}
*/
'resetOthers': false,

/**
* If true, when a fields value has changed, a "change" event will be fired
* @type {boolean}
Expand Down Expand Up @@ -146,6 +153,7 @@ class FormDataJson {

return true
}

const tree = FormDataJson.getFieldTree(el, isValidInput)
const returnObject = {}
const files = []
Expand Down Expand Up @@ -265,6 +273,9 @@ class FormDataJson {
if (options.clearOthers) {
FormDataJson.clear(el)
}
if (options.resetOthers) {
FormDataJson.reset(el)
}

/**
* Recursive set values
Expand Down

0 comments on commit 4a01101

Please sign in to comment.