Skip to content

Commit

Permalink
docs: refactor form examples to typed forms
Browse files Browse the repository at this point in the history
  • Loading branch information
timdeschryver committed Jan 28, 2023
1 parent 52a2586 commit 701dc5e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
9 changes: 5 additions & 4 deletions apps/example-app/src/app/examples/03-forms.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Component } from '@angular/core';
import { UntypedFormBuilder, Validators } from '@angular/forms';
import { FormBuilder, Validators } from '@angular/forms';

@Component({
selector: 'app-fixture',
Expand Down Expand Up @@ -35,13 +35,14 @@ export class FormsComponent {
{ id: 'B', value: 'Blue' },
{ id: 'G', value: 'Green' },
];

form = this.formBuilder.group({
name: ['', Validators.required],
name: ['', [Validators.required]],
score: [0, { validators: [Validators.min(1), Validators.max(10)], updateOn: 'blur' }],
color: ['', Validators.required],
color: [null as string | null, Validators.required],
});

constructor(private formBuilder: UntypedFormBuilder) {}
constructor(private formBuilder: FormBuilder) {}

get formErrors() {
return Object.keys(this.form.controls)
Expand Down
12 changes: 6 additions & 6 deletions apps/example-app/src/app/examples/04-forms-with-material.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Component } from '@angular/core';
import { UntypedFormBuilder, Validators } from '@angular/forms';
import { FormBuilder, Validators } from '@angular/forms';

@Component({
selector: 'app-fixture',
Expand Down Expand Up @@ -74,14 +74,14 @@ export class MaterialFormsComponent {
{ id: 'G', value: 'Green' },
];
form = this.formBuilder.group({
name: ['', Validators.required],
name: ['', [Validators.required]],
score: [0, [Validators.min(1), Validators.max(10)]],
color: [null, Validators.required],
date: [null, Validators.required],
agree: [null, Validators.requiredTrue],
color: [null as string | null, Validators.required],
date: [null as Date | null, Validators.required],
agree: [false, Validators.requiredTrue],
});

constructor(private formBuilder: UntypedFormBuilder) {}
constructor(private formBuilder: FormBuilder) {}

get colorControlDisplayValue(): string | undefined {
const selectedId = this.form.get('color')?.value;
Expand Down

0 comments on commit 701dc5e

Please sign in to comment.