11``` ts
22import { Component } from ' @angular/core' ;
3- import { FormBuilder , FormGroup , Validators , ReactiveFormsModule } from ' @angular/forms' ;
4- import { IonToggle , IonButton } from ' @ionic/angular/standalone' ;
3+ import {
4+ FormBuilder ,
5+ FormGroup ,
6+ Validators ,
7+ ReactiveFormsModule ,
8+ } from ' @angular/forms' ;
9+ import { IonToggle } from ' @ionic/angular/standalone' ;
510
611@Component ({
712 selector: ' app-example' ,
813 standalone: true ,
9- imports: [IonToggle , IonButton , ReactiveFormsModule ],
14+ imports: [IonToggle , ReactiveFormsModule ],
1015 templateUrl: ' ./example.component.html' ,
1116 styleUrl: ' ./example.component.css' ,
1217})
@@ -15,14 +20,13 @@ export class ExampleComponent {
1520
1621 constructor (private fb : FormBuilder ) {
1722 this .myForm = this .fb .group ({
18- wifi: [false , Validators .requiredTrue ],
23+ wifi: [true , Validators .requiredTrue ],
1924 });
2025 }
2126
22- onSubmit() {
23- // Mark the control as touched to trigger the error message.
24- // This is needed if the user submits the form without interacting
25- // with the toggle.
27+ onChange() {
28+ // Mark the control as touched to trigger the error message
29+ // without requiring the toggle to be blurred first
2630 this .myForm .get (' wifi' )! .markAsTouched ();
2731 }
2832}
0 commit comments