-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(docs): need split examples of validation (#UIM-543) (#543)
* feat(docs): need split examples of validation (#UIM-543) WIP * fixed navigation * fixed after UX review * added one more example for composite form
- Loading branch information
1 parent
8a7b20c
commit a96e612
Showing
21 changed files
with
522 additions
and
270 deletions.
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
30 changes: 30 additions & 0 deletions
30
...s/mosaic-examples/mosaic/validation/validation-composite/validation-composite-example.css
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,30 @@ | ||
.docs-form { | ||
color: #999999 | ||
} | ||
|
||
.docs-label { | ||
margin-bottom: 4px; | ||
} | ||
|
||
.docs-hint { | ||
color: #E76E5C; | ||
} | ||
|
||
.docs-composite-form { | ||
width: 600px; | ||
|
||
margin-bottom: 40px; | ||
} | ||
|
||
.docs-column { | ||
width: 200px; | ||
margin-right: 16px; | ||
} | ||
|
||
.layout-row { | ||
margin-bottom: 4px; | ||
} | ||
|
||
.validation-error { | ||
background-color: #FCEFEC; | ||
} |
60 changes: 60 additions & 0 deletions
60
.../mosaic-examples/mosaic/validation/validation-composite/validation-composite-example.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,60 @@ | ||
Проверка во время ввода значения | ||
<div class="layout-margin docs-composite-form" [class.validation-error]="compositeFormWithOnTypeChecking.errors?.range"> | ||
<form class="docs-form" [formGroup]="compositeFormWithOnTypeChecking" novalidate> | ||
<div class="layout-row"> | ||
<div class="docs-column"> | ||
<div class="docs-label">Начало диапазона</div> | ||
<mc-form-field | ||
mcTooltip | ||
[mcTitle]="'Только цифры и точки'" | ||
[mcMouseEnterDelay]="10" | ||
#startTooltip="mcTooltip" | ||
mcTrigger="manual" | ||
mcPlacement="bottom"> | ||
<input mcInput formControlName="start" (input)="onInputStart($event)"> | ||
</mc-form-field> | ||
</div> | ||
|
||
<div class="docs-column"> | ||
<div class="docs-label">Окончание</div> | ||
<mc-form-field | ||
mcTooltip | ||
[mcTitle]="'Только цифры и точки'" | ||
[mcMouseEnterDelay]="10" | ||
#endTooltip="mcTooltip" | ||
mcTrigger="manual" | ||
mcPlacement="bottom"> | ||
<input mcInput formControlName="end" (input)="onInputEnd($event)"> | ||
</mc-form-field> | ||
</div> | ||
</div> | ||
|
||
<mc-hint class="mc-caption docs-hint" *ngIf="compositeFormWithOnTypeChecking.errors?.range">IP-адрес окончания диапазона должен быть больше, чем IP-адрес начала</mc-hint> | ||
</form> | ||
</div> | ||
|
||
|
||
Проверка по уходу с поля | ||
<div class="layout-margin docs-composite-form" [class.validation-error]="compositeFormWithOnBlurChecking.errors?.range"> | ||
<form class="docs-form" [formGroup]="compositeFormWithOnBlurChecking" novalidate> | ||
<div class="layout-row"> | ||
<div class="docs-column"> | ||
<div class="docs-label">Начало диапазона</div> | ||
<mc-form-field> | ||
<input mcInput formControlName="start"> | ||
<mc-hint class="mc-caption docs-hint" *ngIf="compositeFormWithOnBlurChecking.controls.start.invalid">IP-адрес не соответствует стандартам RFC</mc-hint> | ||
</mc-form-field> | ||
</div> | ||
|
||
<div class="docs-column"> | ||
<div class="docs-label">Окончание</div> | ||
<mc-form-field> | ||
<input mcInput formControlName="end"> | ||
<mc-hint class="mc-caption docs-hint" *ngIf="compositeFormWithOnBlurChecking.controls.end.invalid">IP-адрес не соответствует стандартам RFC</mc-hint> | ||
</mc-form-field> | ||
</div> | ||
</div> | ||
|
||
<mc-hint class="mc-caption docs-hint" *ngIf="compositeFormWithOnBlurChecking.errors?.range">IP-адрес окончания диапазона должен быть больше, чем IP-адрес начала</mc-hint> | ||
</form> | ||
</div> |
82 changes: 82 additions & 0 deletions
82
...es/mosaic-examples/mosaic/validation/validation-composite/validation-composite-example.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,82 @@ | ||
import { Component, ViewChild, ViewEncapsulation } from '@angular/core'; | ||
import { AbstractControl, FormControl, FormGroup, ValidationErrors, ValidatorFn, Validators } from '@angular/forms'; | ||
|
||
|
||
function compositeFormValidator(): ValidatorFn { | ||
return (g: AbstractControl | FormGroup): ValidationErrors | null => { | ||
const start = g.get('start')?.value; | ||
const end = g.get('end')?.value; | ||
|
||
if (IP_PATTERN.test(start) && IP_PATTERN.test(end)) { | ||
const parsedStartIp = start.split('.').map((octet) => parseInt(octet, 10)); | ||
const parsedEndIp = end.split('.').map((octet) => parseInt(octet, 10)); | ||
|
||
for (let i = 0; i < parsedStartIp.length; i++) { | ||
if (parsedStartIp[i] > parsedEndIp[i]) { return { range: true }; } | ||
} | ||
} | ||
|
||
return null; | ||
}; | ||
} | ||
|
||
const IP_PATTERN = /^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$/; | ||
|
||
/** | ||
* @title validation-composite | ||
*/ | ||
@Component({ | ||
selector: 'validation-composite-example', | ||
templateUrl: 'validation-composite-example.html', | ||
styleUrls: ['validation-composite-example.css'], | ||
encapsulation: ViewEncapsulation.None | ||
}) | ||
export class ValidationCompositeExample { | ||
compositeFormWithOnTypeChecking: FormGroup; | ||
compositeFormWithOnBlurChecking: FormGroup; | ||
|
||
@ViewChild('startTooltip', { static: false }) startTooltip: any; | ||
@ViewChild('endTooltip', { static: false }) endTooltip: any; | ||
|
||
constructor() { | ||
this.compositeFormWithOnTypeChecking = new FormGroup({ | ||
start: new FormControl('', [Validators.pattern(IP_PATTERN)]), | ||
end: new FormControl('', [Validators.pattern(IP_PATTERN)]) | ||
}, compositeFormValidator()); | ||
|
||
this.compositeFormWithOnBlurChecking = new FormGroup({ | ||
start: new FormControl('', [Validators.pattern(IP_PATTERN)]), | ||
end: new FormControl('', [Validators.pattern(IP_PATTERN)]) | ||
}, compositeFormValidator()); | ||
} | ||
|
||
onInputStart(event) { | ||
const regex = /^[\d\.]+$/g; | ||
|
||
if (!regex.test(event.target.value)) { | ||
event.target.value = event.target.value.replace(/\D+/g, ''); | ||
|
||
if (!this.startTooltip.isTooltipOpen) { | ||
this.startTooltip.show(); | ||
|
||
// tslint:disable-next-line:no-magic-numbers | ||
setTimeout(() => this.startTooltip.hide(), 3000); | ||
} | ||
} | ||
} | ||
|
||
onInputEnd(event) { | ||
const regex = /^[\d\.]+$/g; | ||
|
||
if (!regex.test(event.target.value)) { | ||
event.target.value = event.target.value.replace(/\D+/g, ''); | ||
|
||
if (!this.endTooltip.isTooltipOpen) { | ||
this.endTooltip.show(); | ||
|
||
// tslint:disable-next-line:no-magic-numbers | ||
setTimeout(() => this.endTooltip.hide(), 3000); | ||
} | ||
} | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
packages/mosaic-examples/mosaic/validation/validation-global/validation-global-example.css
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,15 @@ | ||
.docs-form { | ||
color: #999999 | ||
} | ||
|
||
.docs-row { | ||
margin-bottom: 16px; | ||
} | ||
|
||
.docs-label { | ||
margin-bottom: 4px; | ||
} | ||
|
||
.docs-width { | ||
width: 400px; | ||
} |
34 changes: 34 additions & 0 deletions
34
packages/mosaic-examples/mosaic/validation/validation-global/validation-global-example.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,34 @@ | ||
<div class="layout-margin docs-width"> | ||
<div class="mc-alert mc-alert_error" *ngIf="showServerErrors"> | ||
<i mc-icon="mc-info_16" color="error" class="mc-alert__icon"></i> | ||
<div> | ||
<div><b>Не удается получить ответ от сервера</b></div> | ||
При попытке отправить данные сервер не ответил, попробуйте снова | ||
</div> | ||
</div> | ||
|
||
<form class="docs-form" [formGroup]="globalErrorForm" (ngSubmit)="submitGlobalErrorForm()" novalidate> | ||
<div class="docs-row"> | ||
<div class="docs-label">Имя</div> | ||
<mc-form-field> | ||
<input mcInput formControlName="firstName"> | ||
</mc-form-field> | ||
</div> | ||
|
||
<div class="docs-row"> | ||
<div class="docs-label">Фамилия</div> | ||
<mc-form-field> | ||
<input mcInput formControlName="lastName"> | ||
</mc-form-field> | ||
</div> | ||
|
||
<button | ||
mc-button | ||
color="primary" | ||
type="submit" | ||
[class.mc-progress]="inProgress" | ||
[disabled]="inProgress"> | ||
Отправить | ||
</button> | ||
</form> | ||
</div> |
37 changes: 37 additions & 0 deletions
37
packages/mosaic-examples/mosaic/validation/validation-global/validation-global-example.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,37 @@ | ||
import { Component, ViewEncapsulation } from '@angular/core'; | ||
import { FormControl, FormGroup } from '@angular/forms'; | ||
|
||
|
||
/** | ||
* @title validation-global | ||
*/ | ||
@Component({ | ||
selector: 'validation-global-example', | ||
templateUrl: 'validation-global-example.html', | ||
styleUrls: ['validation-global-example.css'], | ||
encapsulation: ViewEncapsulation.None | ||
}) | ||
export class ValidationGlobalExample { | ||
globalErrorForm: FormGroup; | ||
showServerErrors: boolean = false; | ||
inProgress: boolean = false; | ||
|
||
constructor() { | ||
this.globalErrorForm = new FormGroup({ | ||
firstName: new FormControl(''), | ||
lastName: new FormControl(''), | ||
thirdName: new FormControl('') | ||
}); | ||
} | ||
|
||
submitGlobalErrorForm() { | ||
this.showServerErrors = false; | ||
this.inProgress = true; | ||
|
||
setTimeout(() => { | ||
this.showServerErrors = true; | ||
this.inProgress = false; | ||
// tslint:disable-next-line:no-magic-numbers | ||
}, 1000); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
packages/mosaic-examples/mosaic/validation/validation-on-blur/validation-on-blur-example.css
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,15 @@ | ||
.docs-row { | ||
margin-bottom: 16px; | ||
} | ||
|
||
.docs-label { | ||
margin-bottom: 4px; | ||
} | ||
|
||
.docs-width { | ||
width: 400px; | ||
} | ||
|
||
.docs-hint { | ||
color: #E76E5C; | ||
} |
9 changes: 9 additions & 0 deletions
9
...ages/mosaic-examples/mosaic/validation/validation-on-blur/validation-on-blur-example.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,9 @@ | ||
<div class="layout-margin docs-width"> | ||
<div class="docs-row"> | ||
<div class="docs-label">IP-адрес</div> | ||
<mc-form-field> | ||
<input mcInput [formControl]="ipAddress"> | ||
<mc-hint class="mc-caption docs-hint" *ngIf="ipAddress.invalid">IP-адрес не соответствует стандартам RFC</mc-hint> | ||
</mc-form-field> | ||
</div> | ||
</div> |
22 changes: 22 additions & 0 deletions
22
packages/mosaic-examples/mosaic/validation/validation-on-blur/validation-on-blur-example.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,22 @@ | ||
import { Component, ViewEncapsulation } from '@angular/core'; | ||
import { FormControl, Validators } from '@angular/forms'; | ||
|
||
|
||
const IP_PATTERN = /^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$/; | ||
|
||
/** | ||
* @title validation-on-blur | ||
*/ | ||
@Component({ | ||
selector: 'validation-on-blur-example', | ||
templateUrl: 'validation-on-blur-example.html', | ||
styleUrls: ['validation-on-blur-example.css'], | ||
encapsulation: ViewEncapsulation.None | ||
}) | ||
export class ValidationOnBlurExample { | ||
ipAddress: FormControl; | ||
|
||
constructor() { | ||
this.ipAddress = new FormControl('', [Validators.pattern(IP_PATTERN)]); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
packages/mosaic-examples/mosaic/validation/validation-on-type/validation-on-type-example.css
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,15 @@ | ||
.docs-form { | ||
color: #999999 | ||
} | ||
|
||
.docs-row { | ||
margin-bottom: 16px; | ||
} | ||
|
||
.docs-label { | ||
margin-bottom: 4px; | ||
} | ||
|
||
.docs-width { | ||
width: 400px; | ||
} |
16 changes: 16 additions & 0 deletions
16
...ages/mosaic-examples/mosaic/validation/validation-on-type/validation-on-type-example.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,16 @@ | ||
<div class="layout-margin docs-width"> | ||
<form class="docs-form" [formGroup]="checkOnFlyForm" novalidate> | ||
<div class="docs-row"> | ||
<div class="docs-label">Название папки</div> | ||
<mc-form-field | ||
mcTooltip | ||
[mcTitle]="'Только цифры'" | ||
[mcMouseEnterDelay]="10" | ||
#tooltip="mcTooltip" | ||
mcTrigger="manual" | ||
mcPlacement="bottom"> | ||
<input mcInput formControlName="folderName" (input)="onInput($event)"> | ||
</mc-form-field> | ||
</div> | ||
</form> | ||
</div> |
Oops, something went wrong.