diff --git a/CHANGELOG.md b/CHANGELOG.md index f8af1515..5997982d 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +# 6.2.1 (master) +- Refactored set value with input function +- Deprecated input function on `initial` and `default` props. +- Fix: input function applied 2 times when using `set()` + # 6.2.0 (master) - Feat: #433 (File input append mode) diff --git a/src/Base.ts b/src/Base.ts index ea4257b4..f255e950 100755 --- a/src/Base.ts +++ b/src/Base.ts @@ -440,18 +440,12 @@ export default class Base implements BaseInterface { const fallback = this.state.options.get(OptionsEnum.fallback); const x = this.state.struct().findIndex(s => s.startsWith($field.path.replace(/\.\d+\./, '[].') + '[]')); if (!fallback && $field.fields.size === 0 && x < 0) { - $field.value = parseInput($field.$input, { - fallbackValueOption: this.state.options.get(OptionsEnum.fallbackValue, this), - separated: _.get(raw, $path), - }); + $field.value = _.get(raw, $path); return; } } if (_.isNull(field) || _.isNil(field.fields)) { - $field.value = parseInput($field.$input, { - fallbackValueOption: this.state.options.get(OptionsEnum.fallbackValue, this), - separated: field, - }); + $field.value = field; return; } } @@ -571,15 +565,8 @@ export default class Base implements BaseInterface { const deep = (_.isObject(data) && prop === FieldPropsEnum.value) || _.isPlainObject(data); if (deep && this.hasNestedFields) return this.deepSet(prop, data, "", true); - if (([ - FieldPropsEnum.value, - FieldPropsEnum.initial, - FieldPropsEnum.default, - ] as string[]).includes(prop)) { - (this as any)[prop] = parseInput((this as any).$input, { - fallbackValueOption: this.state.options.get(OptionsEnum.fallbackValue, this), - separated: data, - }); + if (prop === FieldPropsEnum.value) { + (this as any).value = data; } else { _.set(this, `$${prop}`, data); } diff --git a/src/Field.ts b/src/Field.ts index 8a063433..725e506a 100755 --- a/src/Field.ts +++ b/src/Field.ts @@ -54,7 +54,7 @@ const setupDefaultProp = ( { isEmptyArray, fallbackValueOption }: { isEmptyArray: boolean, fallbackValueOption: any } ) => - parseInput(instance.$input, { + parseInput((val) => val, { defaultValue, nullable: true, isEmptyArray, @@ -262,16 +262,24 @@ export default class Field extends Base implements FieldInterface { if ( new RegExp("^-?\\d+(,\\d+)*(\\.\\d+([eE]\\d+)?)?$", "g").exec(newVal) ) { - this.$value = _.toNumber(newVal); + this.$value = parseInput(this.$input, { + fallbackValueOption: this.state.options.get(OptionsEnum.fallbackValue, this), + separated: _.toNumber(newVal), + }); + this.$changed ++; - if (!this.resetting && !this.clearing) { + if (!this.actionRunning) { this.state.form.$changed ++; }; return; } } } - this.$value = newVal; + this.$value = parseInput(this.$input, { + fallbackValueOption: this.state.options.get(OptionsEnum.fallbackValue, this), + separated: newVal, + }); + this.$changed ++; if (!this.actionRunning) { this.state.form.$changed ++; @@ -291,17 +299,11 @@ export default class Field extends Base implements FieldInterface { } set initial(val) { - this.$initial = parseInput(this.$input, { - fallbackValueOption: this.state.options.get(OptionsEnum.fallbackValue, this), - separated: val, - }); + this.$initial = val; } set default(val) { - this.$default = parseInput(this.$input, { - fallbackValueOption: this.state.options.get(OptionsEnum.fallbackValue, this), - separated: val, - }); + this.$default = val; } get actionRunning() { @@ -539,7 +541,7 @@ export default class Field extends Base implements FieldInterface { fallback: $props.$initial, }); - this.$initial = parseInput(this.$input, { + this.$initial = parseInput((val) => val, { fallbackValueOption, nullable: true, isEmptyArray, @@ -572,7 +574,7 @@ export default class Field extends Base implements FieldInterface { separated: $props.$value, }); - this.$initial = parseInput(this.$input, { + this.$initial = parseInput((val) => val, { fallbackValueOption, nullable: true, isEmptyArray, @@ -821,10 +823,7 @@ export default class Field extends Base implements FieldInterface { const fallback = this.state.options.get(OptionsEnum.fallback, this); const x = this.state.struct().findIndex(s => s.startsWith(this.path.replace(/\.\d+\./, '[].') + '[]')); if (!fallback && this.fields.size === 0 && x < 0) { - this.value = parseInput(this.$input, { - fallbackValueOption: this.state.options.get(OptionsEnum.fallbackValue, this), - separated: fields, - }); + this.value = fields; return; } super.update(fields);