@sprucelabs/heartwood-view-controllers 122.1.3 → 122.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -31,6 +31,7 @@ export default class FormViewController<S extends Schema, V extends ViewModel<S>
|
|
|
31
31
|
private emitOnChange;
|
|
32
32
|
private buildChangeOptions;
|
|
33
33
|
setValues(values: SchemaPartialValues<S>): Promise<void>;
|
|
34
|
+
private getWasConstructedWithValues;
|
|
34
35
|
private normalizeValues;
|
|
35
36
|
private validateDirtyFields;
|
|
36
37
|
setErrors(errors: TypedFieldError<S>[]): void;
|
|
@@ -210,12 +210,20 @@ export default class FormViewController extends AbstractViewController {
|
|
|
210
210
|
if (shouldBail === false) {
|
|
211
211
|
return;
|
|
212
212
|
}
|
|
213
|
+
if (!this.getWasConstructedWithValues()) {
|
|
214
|
+
this.originalValues = Object.assign({}, values);
|
|
215
|
+
}
|
|
213
216
|
this.model.values = this.normalizeValues(values);
|
|
214
217
|
const errorsByField = this.validateDirtyFields();
|
|
215
218
|
yield this.emitOnChange(errorsByField);
|
|
216
219
|
this.triggerRender();
|
|
217
220
|
});
|
|
218
221
|
}
|
|
222
|
+
getWasConstructedWithValues() {
|
|
223
|
+
return Object.keys(this.originalValues).find((k) => k in this.originalValues &&
|
|
224
|
+
typeof this.originalValues[k] !==
|
|
225
|
+
'undefined');
|
|
226
|
+
}
|
|
219
227
|
normalizeValues(values, fields) {
|
|
220
228
|
if (!this.model.schema) {
|
|
221
229
|
return values;
|
|
@@ -31,6 +31,7 @@ export default class FormViewController<S extends Schema, V extends ViewModel<S>
|
|
|
31
31
|
private emitOnChange;
|
|
32
32
|
private buildChangeOptions;
|
|
33
33
|
setValues(values: SchemaPartialValues<S>): Promise<void>;
|
|
34
|
+
private getWasConstructedWithValues;
|
|
34
35
|
private normalizeValues;
|
|
35
36
|
private validateDirtyFields;
|
|
36
37
|
setErrors(errors: TypedFieldError<S>[]): void;
|
|
@@ -194,11 +194,21 @@ class FormViewController extends Abstract_vc_1.default {
|
|
|
194
194
|
if (shouldBail === false) {
|
|
195
195
|
return;
|
|
196
196
|
}
|
|
197
|
+
if (!this.getWasConstructedWithValues()) {
|
|
198
|
+
this.originalValues = {
|
|
199
|
+
...values,
|
|
200
|
+
};
|
|
201
|
+
}
|
|
197
202
|
this.model.values = this.normalizeValues(values);
|
|
198
203
|
const errorsByField = this.validateDirtyFields();
|
|
199
204
|
await this.emitOnChange(errorsByField);
|
|
200
205
|
this.triggerRender();
|
|
201
206
|
}
|
|
207
|
+
getWasConstructedWithValues() {
|
|
208
|
+
return Object.keys(this.originalValues).find((k) => k in this.originalValues &&
|
|
209
|
+
typeof this.originalValues[k] !==
|
|
210
|
+
'undefined');
|
|
211
|
+
}
|
|
202
212
|
normalizeValues(values, fields) {
|
|
203
213
|
if (!this.model.schema) {
|
|
204
214
|
return values;
|
package/package.json
CHANGED