@@ -209,21 +209,24 @@ export class FormState<T extends object, State = DefaultState, Error extends str
209209 fireAny : boolean = true
210210 ) {
211211 // value can contain the default value or normal value. (Determined by isDefault)
212+ let other = isDefault ? this . values [ key ] : this . defaultValues [ key ] ;
212213 if ( typeof value === "object" && value !== null ) {
213214 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+ }
221224 }
222225
223226 this . setValueInternal ( key , value , dirty , validate , isDefault , notifyChild , notifyParent , fireAny ) ;
224227 } else {
225228 // 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 ;
227230 if ( ( isDefault ? this . defaultValues [ key ] : this . values [ key ] ) === value && this . dirtyMap [ key ] === dirty ) {
228231 return ;
229232 }
0 commit comments