-
Notifications
You must be signed in to change notification settings - Fork 475
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(demo):
InputDateTime
add example with custom validator
- Loading branch information
Showing
4 changed files
with
102 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
projects/demo/src/modules/components/input-date-time/examples/7/index.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<form [formGroup]="testForm"> | ||
<tui-input-date-time formControlName="testValue">Choose date and time</tui-input-date-time> | ||
<tui-error | ||
formControlName="testValue" | ||
[error]="[] | tuiFieldError | async" | ||
></tui-error> | ||
|
||
<p>Form value:</p> | ||
|
||
<pre><code>{{ testForm.value | json }}</code></pre> | ||
</form> |
44 changes: 44 additions & 0 deletions
44
projects/demo/src/modules/components/input-date-time/examples/7/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import {AsyncPipe, JsonPipe} from '@angular/common'; | ||
import {Component} from '@angular/core'; | ||
import { | ||
AbstractControl, | ||
FormControl, | ||
FormGroup, | ||
ReactiveFormsModule, | ||
type ValidationErrors, | ||
type ValidatorFn, | ||
} from '@angular/forms'; | ||
import {changeDetection} from '@demo/emulate/change-detection'; | ||
import {encapsulation} from '@demo/emulate/encapsulation'; | ||
import {TuiDay} from '@taiga-ui/cdk'; | ||
import {TuiError} from '@taiga-ui/core'; | ||
import {TuiFieldErrorPipe} from '@taiga-ui/kit'; | ||
import {TuiInputDateTimeModule} from '@taiga-ui/legacy'; | ||
|
||
const completeDateTimeValidator: ValidatorFn = ( | ||
control: AbstractControl, | ||
): ValidationErrors | null => | ||
control.value.every(Boolean) ? null : {incompleteDateTime: true}; | ||
|
||
@Component({ | ||
standalone: true, | ||
imports: [ | ||
AsyncPipe, | ||
JsonPipe, | ||
ReactiveFormsModule, | ||
TuiInputDateTimeModule, | ||
TuiError, | ||
TuiFieldErrorPipe, | ||
], | ||
templateUrl: './index.html', | ||
encapsulation, | ||
changeDetection, | ||
}) | ||
export default class Example { | ||
protected readonly testForm = new FormGroup({ | ||
testValue: new FormControl( | ||
[new TuiDay(2017, 2, 15), null], | ||
completeDateTimeValidator, | ||
), | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters