@@ -209,21 +209,24 @@ export class FormState<T extends object, State = DefaultState, Error extends str
209
209
fireAny : boolean = true
210
210
) {
211
211
// value can contain the default value or normal value. (Determined by isDefault)
212
+ let other = isDefault ? this . values [ key ] : this . defaultValues [ key ] ;
212
213
if ( typeof value === "object" && value !== null ) {
213
214
let dirty : boolean | undefined = false ;
214
- if ( value instanceof Date ) {
215
- // Compare date objects
216
- dirty = value ?. getTime ( ) !== ( isDefault ? this . values [ key ] : ( this . defaultValues [ key ] as any ) ) ?. getTime ( ) ;
217
- } else if ( ! ( key in this . childMap ) ) {
218
- // Compare objects if there is no child form, because it calculates the dirty value for us
219
- let other = isDefault ? this . values [ key ] : this . defaultValues [ key ] ;
220
- dirty = JSON . stringify ( value ) !== JSON . stringify ( other ) ;
215
+
216
+ // Compare objects if there is no child form, because it calculates the dirty value for us
217
+ if ( ! ( key in this . childMap ) ) {
218
+ if ( value instanceof Date && other instanceof Date ) {
219
+ // Compare date objects
220
+ dirty = value ?. getTime ( ) !== other ?. getTime ( ) ;
221
+ } else {
222
+ dirty = JSON . stringify ( value ) !== JSON . stringify ( other ) ;
223
+ }
221
224
}
222
225
223
226
this . setValueInternal ( key , value , dirty , validate , isDefault , notifyChild , notifyParent , fireAny ) ;
224
227
} else {
225
228
// Compare value and existing value/defaultValue which determines dirty
226
- let dirty = value !== ( isDefault ? this . values [ key ] : this . defaultValues [ key ] ) ;
229
+ let dirty = value !== other ;
227
230
if ( ( isDefault ? this . defaultValues [ key ] : this . values [ key ] ) === value && this . dirtyMap [ key ] === dirty ) {
228
231
return ;
229
232
}
0 commit comments