Skip to content

Commit 5e57f17

Browse files
committed
Move custom step validation function so that users can simply import and use
1 parent 5d78514 commit 5e57f17

File tree

3 files changed

+26
-23
lines changed

3 files changed

+26
-23
lines changed

src/cdk/stepper/stepper.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,7 @@ export class CdkStep {
6565
private _disabled = false;
6666

6767
/** Whether user has seen the expanded step content or not . */
68-
get interacted() { return this._interacted; }
69-
set interacted(value: boolean) {
70-
this._interacted = value;
71-
}
72-
private _interacted = false;
68+
interacted = false;
7369

7470
/** Label of the step. */
7571
@Input()

src/demo-app/stepper/stepper-demo.ts

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import {Component} from '@angular/core';
2-
import {
3-
Validators, FormBuilder, FormGroup, FormArray, ValidationErrors, ValidatorFn
4-
} from '@angular/forms';
2+
import {Validators, FormBuilder, FormGroup} from '@angular/forms';
3+
import {stepValidator} from '@angular/material';
54

65
@Component({
76
moduleId: module.id,
@@ -34,20 +33,7 @@ export class StepperDemo {
3433
this._formBuilder.group({
3534
phoneFormCtrl: [''],
3635
})
37-
], this._stepValidator)
36+
], stepValidator)
3837
});
3938
}
40-
41-
/**
42-
* Form array validator to check if all form groups in form array are valid.
43-
* If not, it will return the index of the first invalid form group.
44-
*/
45-
private _stepValidator: ValidatorFn = (formArray: FormArray): ValidationErrors | null => {
46-
for (let i = 0; i < formArray.length; i++) {
47-
if (formArray.at(i).invalid) {
48-
return {'invalid step': {'index': i}};
49-
}
50-
}
51-
return null;
52-
}
5339
}

src/lib/stepper/stepper.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,28 @@ import {
2828
MD_ERROR_GLOBAL_OPTIONS,
2929
ErrorStateMatcher
3030
} from '../core/error/error-options';
31-
import {FormControl, FormGroupDirective, NgForm} from '@angular/forms';
31+
import {
32+
FormArray, FormControl, FormGroupDirective, NgForm, ValidationErrors,
33+
ValidatorFn
34+
} from '@angular/forms';
35+
36+
/**
37+
* Form array validator to check if all form groups in form array are valid.
38+
* If not, it will return the index of the first invalid form group.
39+
*/
40+
export const stepValidator: ValidatorFn = (formArray: FormArray): ValidationErrors | null => {
41+
for (let i = 0; i < formArray.length; i++) {
42+
if (formArray.at(i).invalid) {
43+
return {'invalid step': {'index': i}};
44+
}
45+
}
46+
return null;
47+
};
48+
49+
/**
50+
* Form array validator to check if all form groups in form array are valid.
51+
* If not, it will return the index of the first invalid form group.
52+
*/
3253

3354
@Component({
3455
moduleId: module.id,

0 commit comments

Comments
 (0)