Skip to content

Commit cd989e3

Browse files
committed
chore(tests): validate checkbox and toggle in angular lazy template-form
1 parent 2be39da commit cd989e3

File tree

6 files changed

+61
-4
lines changed

6 files changed

+61
-4
lines changed

packages/angular/test/base/src/app/lazy/app-lazy/app.module.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import { AlertComponent } from '../alert/alert.component';
2828
import { AccordionComponent } from '../accordion/accordion.component';
2929
import { AccordionModalComponent } from '../accordion/accordion-modal/accordion-modal.component';
3030
import { TabsBasicComponent } from '../tabs-basic/tabs-basic.component';
31-
import { TemplateFormComponent } from '../template-form/template-form.component';
3231

3332
@NgModule({
3433
declarations: [
@@ -54,8 +53,7 @@ import { TemplateFormComponent } from '../template-form/template-form.component'
5453
AlertComponent,
5554
AccordionComponent,
5655
AccordionModalComponent,
57-
TabsBasicComponent,
58-
TemplateFormComponent
56+
TabsBasicComponent
5957
],
6058
imports: [
6159
CommonModule,

packages/angular/test/base/src/app/lazy/app-lazy/app.routes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export const routes: Routes = [
3434
{ path: 'textarea', loadChildren: () => import('../textarea/textarea.module').then(m => m.TextareaModule) },
3535
{ path: 'searchbar', loadChildren: () => import('../searchbar/searchbar.module').then(m => m.SearchbarModule) },
3636
{ path: 'form', component: FormComponent },
37-
{ path: 'template-form', component: TemplateFormComponent },
37+
{ path: 'template-form', loadChildren: () => import('../template-form/template-form.module').then(m => m.TemplateFormModule) },
3838
{ path: 'modals', component: ModalComponent },
3939
{ path: 'modal-inline', loadChildren: () => import('../modal-inline').then(m => m.ModalInlineModule) },
4040
{ path: 'modal-sheet-inline', loadChildren: () => import('../modal-sheet-inline').then(m => m.ModalSheetInlineModule) },
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { NgModule } from "@angular/core";
2+
import { RouterModule } from "@angular/router";
3+
import { TemplateFormComponent } from "./template-form.component";
4+
5+
@NgModule({
6+
imports: [
7+
RouterModule.forChild([
8+
{
9+
path: '',
10+
component: TemplateFormComponent
11+
}
12+
])
13+
],
14+
exports: [RouterModule]
15+
})
16+
export class TemplateFormRoutingModule { }

packages/angular/test/base/src/app/lazy/template-form/template-form.component.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@
109109
[(ngModel)]="checkboxValue"
110110
name="checkboxField"
111111
required
112+
requireTrue
112113
#checkboxField="ngModel"
113114
id="template-checkbox-test"
114115
helper-text="You must agree to continue"
@@ -133,6 +134,7 @@
133134
[(ngModel)]="toggleValue"
134135
name="toggleField"
135136
required
137+
requireTrue
136138
#toggleField="ngModel"
137139
id="template-toggle-test"
138140
helper-text="You must turn on to continue"
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { CommonModule } from "@angular/common";
2+
import { NgModule } from "@angular/core";
3+
import { FormsModule, ReactiveFormsModule } from "@angular/forms";
4+
import { IonicModule } from "@ionic/angular";
5+
6+
import { TemplateFormRoutingModule } from "./template-form-routing.module";
7+
import { TemplateFormComponent } from "./template-form.component";
8+
import { RequireTrueValidatorDirective } from "../validators/require-true.directive";
9+
10+
@NgModule({
11+
imports: [
12+
CommonModule,
13+
FormsModule,
14+
ReactiveFormsModule,
15+
IonicModule,
16+
TemplateFormRoutingModule,
17+
RequireTrueValidatorDirective
18+
],
19+
declarations: [
20+
TemplateFormComponent
21+
]
22+
})
23+
export class TemplateFormModule { }
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { Directive, forwardRef } from '@angular/core';
2+
import { NG_VALIDATORS, Validator, AbstractControl, ValidationErrors, Validators } from '@angular/forms';
3+
4+
@Directive({
5+
selector: '[requireTrue]',
6+
providers: [
7+
{
8+
provide: NG_VALIDATORS,
9+
useExisting: forwardRef(() => RequireTrueValidatorDirective),
10+
multi: true,
11+
},
12+
],
13+
})
14+
export class RequireTrueValidatorDirective implements Validator {
15+
validate(control: AbstractControl): ValidationErrors | null {
16+
return Validators.requiredTrue(control);
17+
}
18+
}

0 commit comments

Comments
 (0)