Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add input validation for add child form #862

Merged
merged 4 commits into from
Feb 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<ng-container *ngIf = "type === 'validTextField' && forbiddenCharacter && invalid; then incorrectTextField"></ng-container>
<ng-container *ngIf = "type === 'validAddressField' && forbiddenCharacter && invalid; then incorrectAddressField"></ng-container>
<ng-container *ngIf = "type === 'validBuildingNumberField' && forbiddenCharacter && invalid; then incorrectBuildingNumberField"></ng-container>
<ng-container *ngIf = "type === 'validLength' && (minLength || maxLength) && invalid; then invalidLength"></ng-container>

<ng-template #requiredInput>
<small appValidationMessageStyling>
Expand Down Expand Up @@ -47,4 +48,10 @@
<small appValidationMessageStyling>
"Перевірте введені данні. <br> Використовуйте будь ласка тільки кирилицю, цифри та символи ( ' - / , . )"
</small>
</ng-template>

<ng-template #invalidLength>
<small appValidationMessageStyling>
"Це поле має містити від {{ minCharachters }} до {{ maxCharachters }} символів"
</small>
</ng-template>
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ export class ValidationHintForInputComponent {
@Input() isEmailCheck: boolean;
@Input() isEmptyCheck: boolean;
@Input() minLength: boolean;
@Input() maxLength: boolean;
@Input() minCharachters: number;
@Input() maxCharachters: number;
@Input() forbiddenCharacter: string;

constructor() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@
[invalid]="ChildFormGroup.get('lastName').invalid && ChildFormGroup.get('lastName').touched"
[forbiddenCharacter]="ChildFormGroup.get('lastName').errors?.pattern?.requiredPattern">
</app-validation-hint-for-input>
<app-validation-hint-for-input type="validLength"
[minLength]="ChildFormGroup.get('lastName').errors?.minlength"
[maxLength]="ChildFormGroup.get('lastName').errors?.maxlength"
[invalid]="ChildFormGroup.get('lastName').invalid && ChildFormGroup.get('lastName').touched"
[minCharachters]="1"
[maxCharachters]="30">
</app-validation-hint-for-input>

<label class="step-label">Ім'я<span class="step-required">*</span></label>
<mat-form-field>
Expand All @@ -26,6 +33,13 @@
[invalid]="ChildFormGroup.get('firstName').invalid && ChildFormGroup.get('firstName').touched"
[forbiddenCharacter]="ChildFormGroup.get('firstName').errors?.pattern?.requiredPattern">
</app-validation-hint-for-input>
<app-validation-hint-for-input type="validLength"
[minLength]="ChildFormGroup.get('firstName').errors?.minlength"
[maxLength]="ChildFormGroup.get('firstName').errors?.maxlength"
[invalid]="ChildFormGroup.get('firstName').invalid && ChildFormGroup.get('firstName').touched"
[minCharachters]="1"
[maxCharachters]="30">
</app-validation-hint-for-input>

<label class="step-label">По-батькові<span class="step-required">*</span></label>
<mat-form-field>
Expand All @@ -39,6 +53,13 @@
[invalid]="ChildFormGroup.get('middleName').invalid && ChildFormGroup.get('middleName').touched"
[forbiddenCharacter]="ChildFormGroup.get('middleName').errors?.pattern?.requiredPattern">
</app-validation-hint-for-input>
<app-validation-hint-for-input type="validLength"
[minLength]="ChildFormGroup.get('middleName').errors?.minlength"
[maxLength]="ChildFormGroup.get('middleName').errors?.maxlength"
[invalid]="ChildFormGroup.get('middleName').invalid && ChildFormGroup.get('middleName').touched"
[minCharachters]="1"
[maxCharachters]="30">
</app-validation-hint-for-input>

<label class="step-label">Дата народження<span class="step-required">*</span></label>
<mat-form-field appPlaceholderStyling class="step-input step-input-date" floatLabel="never">
Expand Down Expand Up @@ -74,11 +95,33 @@
<mat-form-field>
<input matInput class="step-input" type="text" formControlName="placeOfLiving" autocomplete="none">
</mat-form-field>
<app-validation-hint-for-input type="validAddressField"
[invalid]="ChildFormGroup.get('placeOfLiving').invalid && ChildFormGroup.get('placeOfLiving').touched"
[forbiddenCharacter]="ChildFormGroup.get('placeOfLiving').errors?.pattern?.requiredPattern">
</app-validation-hint-for-input>
<app-validation-hint-for-input type="validLength"
[minLength]="ChildFormGroup.get('placeOfLiving').errors?.minlength"
[maxLength]="ChildFormGroup.get('placeOfLiving').errors?.maxlength"
[invalid]="ChildFormGroup.get('placeOfLiving').invalid && ChildFormGroup.get('placeOfLiving').touched"
[minCharachters]="10"
[maxCharachters]="256">
</app-validation-hint-for-input>

<label class="step-label">Місце навчання (заклад)</label>
<mat-form-field>
<input matInput class="step-input" type="text" formControlName="placeOfStudy" autocomplete="none">
</mat-form-field>
<app-validation-hint-for-input type="validAddressField"
[invalid]="ChildFormGroup.get('placeOfStudy').invalid && ChildFormGroup.get('placeOfStudy').touched"
[forbiddenCharacter]="ChildFormGroup.get('placeOfStudy').errors?.pattern?.requiredPattern">
</app-validation-hint-for-input>
<app-validation-hint-for-input type="validLength"
[minLength]="ChildFormGroup.get('placeOfStudy').errors?.minlength"
[maxLength]="ChildFormGroup.get('placeOfStudy').errors?.maxlength"
[invalid]="ChildFormGroup.get('placeOfStudy').invalid && ChildFormGroup.get('placeOfStudy').touched"
[minCharachters]="10"
[maxCharachters]="256">
</app-validation-hint-for-input>

<label class="step-label">Серія та номер свідоцтва про народження</label>
<mat-form-field>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ class MockValidationHintForInputComponent {
@Input() isEmailCheck: boolean;
@Input() isEmptyCheck: boolean;
@Input() minLength: boolean;
@Input() maxLength: boolean;
@Input() minCharachters: number;
@Input() maxCharachters: number;
@Input() forbiddenCharacter: string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { MetaDataState } from 'src/app/shared/store/meta-data.state';
import { AddNavPath } from 'src/app/shared/store/navigation.actions';
import { RegistrationState } from 'src/app/shared/store/registration.state';
import { CreateChildren, UpdateChild } from 'src/app/shared/store/user.actions';
import { TEXT_REGEX } from 'src/app/shared/constants/regex-constants';
import { TEXT_REGEX, TEXT_WITH_DIGITS_REGEX } from 'src/app/shared/constants/regex-constants';
import { Constants } from 'src/app/shared/constants/constants';
import { CreateFormComponent } from '../../create-form/create-form.component';

Expand Down Expand Up @@ -90,15 +90,38 @@ export class CreateChildComponent extends CreateFormComponent implements OnInit,
*/
private newForm(child?: Child): FormGroup {
const childFormGroup = this.fb.group({
lastName: new FormControl('', [Validators.required, Validators.pattern(TEXT_REGEX)]),
firstName: new FormControl('', [Validators.required, Validators.pattern(TEXT_REGEX)]),
middleName: new FormControl('', [Validators.required, Validators.pattern(TEXT_REGEX)]),
lastName: new FormControl('', [
Validators.required,
Validators.pattern(TEXT_REGEX),
Validators.minLength(1),
Validators.maxLength(30)
]),
firstName: new FormControl('', [
Validators.required,
Validators.pattern(TEXT_REGEX),
Validators.minLength(1),
Validators.maxLength(30)
]),
middleName: new FormControl('', [
Validators.required,
Validators.pattern(TEXT_REGEX),
Validators.minLength(1),
Validators.maxLength(30)
]),
dateOfBirth: new FormControl('', Validators.required),
gender: new FormControl('', Validators.required),
socialGroupId: new FormControl(Constants.SOCIAL_GROUP_ID_ABSENT_VALUE),
placeOfStudy: new FormControl(''),
placeOfLiving: new FormControl(''),
placeOfLiving: new FormControl('', [
Validators.pattern(TEXT_WITH_DIGITS_REGEX),
Validators.minLength(10),
Validators.maxLength(256)
]),
certificateOfBirth: new FormControl(''),
placeOfStudy: new FormControl('', [
Validators.pattern(TEXT_WITH_DIGITS_REGEX),
Validators.minLength(10),
Validators.maxLength(256)
])
});

this.subscribeOnDirtyForm(childFormGroup);
Expand Down