Skip to content

Commit

Permalink
fix: ignore initial value to set dirty state
Browse files Browse the repository at this point in the history
  • Loading branch information
timdeschryver committed Feb 7, 2024
1 parent 8803445 commit c628840
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
7 changes: 5 additions & 2 deletions apps/example/src/app/basic-form/basic-form.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { CustomErrorComponent } from '../custom-input-error.component';
<div>
<button (click)="reset()">Reset form</button>
<button (click)="prefill()">Prefill form</button>
<h3>States</h3>
<pre
Expand Down Expand Up @@ -85,7 +86,9 @@ export default class BasicFormComponent {
this.form.reset();
}

setForm() {
// TODO: allow form values to be set
prefill() {
// TODO: improve this API to set form groups
this.form.controls.age.value.set(42);
this.form.controls.name.value.set('Bob');
}
}
5 changes: 4 additions & 1 deletion packages/platform/src/lib/form-field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,14 @@ export function createFormField<Value>(
const disabledSignal = signal(false);
const readOnlySignal = signal(false);

let previousValue: unknown|undefined = undefined;
effect(
() => {
if (valueSignal()) {
const newValue = valueSignal();
if (previousValue !== undefined && newValue !== previousValue) {
dirtyStateSignal.set('DIRTY');
}
previousValue = newValue;
},
{
allowSignalWrites: true,
Expand Down

0 comments on commit c628840

Please sign in to comment.