diff --git a/CHANGELOG.md b/CHANGELOG.md index 87e5b5e..1a490fc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/src/form-data-json.js b/src/form-data-json.js index e348b68..638c632 100644 --- a/src/form-data-json.js +++ b/src/form-data-json.js @@ -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} @@ -146,6 +153,7 @@ class FormDataJson { return true } + const tree = FormDataJson.getFieldTree(el, isValidInput) const returnObject = {} const files = [] @@ -265,6 +273,9 @@ class FormDataJson { if (options.clearOthers) { FormDataJson.clear(el) } + if (options.resetOthers) { + FormDataJson.reset(el) + } /** * Recursive set values