-
Notifications
You must be signed in to change notification settings - Fork 474
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(demo): add form example for tui-checkbox
- Loading branch information
Showing
5 changed files
with
103 additions
and
1 deletion.
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
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
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
45 changes: 45 additions & 0 deletions
45
projects/demo/src/modules/components/checkbox-labeled/examples/3/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,45 @@ | ||
<ng-container *ngIf="currentQuestion < 2; else result"> | ||
<p>{{ currentQuestion + 1 }}. {{ questionTitles[currentQuestion] }}</p> | ||
|
||
<form [formGroup]="form"> | ||
<tui-checkbox-labeled | ||
*ngFor="let option of questions[currentQuestion]; let index = index" | ||
class="tui-space_top-2" | ||
[formControlName]="index" | ||
> | ||
{{ option }} | ||
</tui-checkbox-labeled> | ||
</form> | ||
|
||
<button | ||
size="s" | ||
tuiButton | ||
type="button" | ||
class="tui-space_top-4" | ||
(click)="nextQuestion()" | ||
> | ||
Next | ||
</button> | ||
</ng-container> | ||
|
||
<ng-template #result> | ||
<p> | ||
<b>Your answers</b> | ||
</p> | ||
|
||
<div | ||
*ngFor="let options of results; let i = index" | ||
class="tui-space_top-4" | ||
> | ||
<p>{{ i + 1 }}. {{ questionTitles[i] }}</p> | ||
|
||
<tui-checkbox-labeled | ||
*ngFor="let question of questions[i]; let j = index" | ||
class="tui-space_top-2" | ||
[ngModel]="options[j]" | ||
[readOnly]="true" | ||
> | ||
{{ question }} | ||
</tui-checkbox-labeled> | ||
</div> | ||
</ng-template> |
41 changes: 41 additions & 0 deletions
41
projects/demo/src/modules/components/checkbox-labeled/examples/3/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,41 @@ | ||
import {Component} from '@angular/core'; | ||
import {FormControl, FormGroup} from '@angular/forms'; | ||
import {changeDetection} from '@demo/emulate/change-detection'; | ||
import {encapsulation} from '@demo/emulate/encapsulation'; | ||
|
||
@Component({ | ||
selector: 'tui-checkbox-labeled-example-3', | ||
templateUrl: './index.html', | ||
encapsulation, | ||
changeDetection, | ||
}) | ||
export class TuiCheckboxLabeledExample3 { | ||
readonly questionTitles = ['Do you like Angular?', 'Do you like Taiga UI?']; | ||
|
||
readonly questions = [ | ||
['Yes', 'No', 'Other'], | ||
['Yes', 'No', 'Other'], | ||
]; | ||
|
||
currentQuestion = 0; | ||
|
||
results: boolean[][] = []; | ||
|
||
form = new FormGroup({ | ||
0: new FormControl(false), | ||
1: new FormControl(false), | ||
2: new FormControl(false), | ||
}); | ||
|
||
nextQuestion(): void { | ||
this.currentQuestion++; | ||
|
||
this.results.push(Object.values(this.form.value).map(Boolean)); | ||
|
||
this.form = new FormGroup({ | ||
0: new FormControl(false), | ||
1: new FormControl(false), | ||
2: new FormControl(false), | ||
}); | ||
} | ||
} |