Skip to content

Commit

Permalink
fix: correct FormGroup array types with fields
Browse files Browse the repository at this point in the history
  • Loading branch information
timdeschryver committed Feb 6, 2024
1 parent 90d7705 commit 013929c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
20 changes: 18 additions & 2 deletions apps/example/src/app/simple-form/simple-form.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,16 @@ import { CustomErrorComponent } from '../custom-input-error.component';
/>
</div>
<div>
<fieldset>
<legend>Team members</legend>
<div *ngFor="let member of form.controls.team.controls(); let i = index;">
<label for="member-{{i}}">Member</label>
<input ngModel [formField]="member" id="member-{{i}}" />
</div>
</fieldset>
<fieldset>
<legend>Todos</legend>
<button (click)="addTodo()">Add todo</button>
<small>{{ form.controls.todos.errors() | json }}</small>
Expand All @@ -77,7 +86,7 @@ import { CustomErrorComponent } from '../custom-input-error.component';
/>
<input ngModel [formField]="todo.controls.description" />
</div>
</div>
</fieldset>
<button (click)="form.markAllAsTouched()">Mark all as touched</button>
<button (click)="reset()">Reset form</button>
Expand Down Expand Up @@ -168,7 +177,14 @@ export default class SimpleFormComponent {
validators: [V.minLength(1)],
}
),

team: this.sfb.createFormGroup([
this.sfb.createFormField(''),
this.sfb.createFormField(''),
this.sfb.createFormField(''),
]),
};

});

createTodo = () => {
Expand Down
2 changes: 2 additions & 0 deletions packages/platform/src/lib/form-group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ export type FormGroup<Fields extends FormGroupCreatorOrSignal = {}> = {
value: Signal<UnwrappedFormGroup<Fields>>;
controls: Fields extends WritableSignal<FormGroup<infer G>[]>
? FormGroupFields<Fields> & WritableSignal<FormGroup<G>[]>
: Fields extends WritableSignal<infer F>
? FormGroupFields<Fields> & WritableSignal<F>
: FormGroupFields<Fields>;
valid: Signal<boolean>;
state: Signal<ValidationState>;
Expand Down

0 comments on commit 013929c

Please sign in to comment.