| 19 | * status, as well as derived logical state. |
| 20 | */ |
| 21 | export class FieldNodeState { |
| 22 | /** |
| 23 | * Indicates whether this field has been touched directly by the user (as opposed to indirectly by |
| 24 | * touching a child field). |
| 25 | * |
| 26 | * A field is considered directly touched when a user stops editing it for the first time (i.e. on blur) |
| 27 | */ |
| 28 | private readonly selfTouched = signal(false); |
| 29 | |
| 30 | /** |
| 31 | * Indicates whether this field has been dirtied directly by the user (as opposed to indirectly by |
| 32 | * dirtying a child field). |
| 33 | * |
| 34 | * A field is considered directly dirtied if a user changed the value of the field at least once. |
| 35 | */ |
| 36 | private readonly selfDirty = signal(false); |
| 37 | |
| 38 | /** |
| 39 | * Marks this specific field as touched. |
| 40 | */ |
| 41 | markAsTouched(): void { |
| 42 | this.selfTouched.set(true); |
| 43 | } |
| 44 | |
| 45 | /** |
| 46 | * Marks this specific field as dirty. |
| 47 | */ |
| 48 | markAsDirty(): void { |
| 49 | this.selfDirty.set(true); |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * Marks this specific field as not dirty. |
| 54 | */ |
| 55 | markAsPristine(): void { |
| 56 | this.selfDirty.set(false); |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * Marks this specific field as not touched. |
| 61 | */ |
| 62 | markAsUntouched(): void { |
| 63 | this.selfTouched.set(false); |
| 64 | } |
| 65 | |
| 66 | /** The {@link FormField} directives that bind this field to a UI control. */ |
| 67 | readonly formFieldBindings = signal<readonly FormField<unknown>[]>([]); |
| 68 | |
| 69 | constructor(private readonly node: FieldNode) {} |
| 70 | |
| 71 | /** |
| 72 | * Whether this field is considered dirty. |
| 73 | * |
| 74 | * A field is considered dirty if one of the following is true: |
| 75 | * - It was directly dirtied and is interactive |
| 76 | * - One of its children is considered dirty |
| 77 | */ |
| 78 | readonly dirty: Signal<boolean> = computed(() => { |
nothing calls this directly
no test coverage detected
searching dependent graphs…