[ADF-3238] content size min error added (#3532)

* content size min error added

* clean code
This commit is contained in:
bbcodrin 2018-06-27 11:38:57 +03:00 committed by Eugenio Romano
parent f7aaafed86
commit 8cc07f5816
3 changed files with 11 additions and 5 deletions

View File

@ -5,7 +5,7 @@
matInput [formControl]="from" [errorStateMatcher]="matcher"
placeholder="{{ 'SEARCH.FILTER.RANGE.FROM' | translate }}"
autocomplete="off">
<mat-error *ngIf="from.hasError('pattern')">
<mat-error *ngIf="from.hasError('pattern') || from.hasError('min')">
{{ 'SEARCH.FILTER.VALIDATION.INVALID-FORMAT' | translate }}
</mat-error>
<mat-error *ngIf="from.hasError('required')">
@ -18,7 +18,7 @@
matInput [formControl]="to" [errorStateMatcher]="matcher"
placeholder="{{ 'SEARCH.FILTER.RANGE.TO' | translate }}"
autocomplete="off">
<mat-error *ngIf="to.hasError('pattern')">
<mat-error *ngIf="to.hasError('pattern') || to.hasError('min')">
{{ 'SEARCH.FILTER.VALIDATION.INVALID-FORMAT' | translate }}
</mat-error>
<mat-error *ngIf="to.hasError('required')">

View File

@ -160,4 +160,10 @@ describe('SearchNumberRangeComponent', () => {
component.from = new FormControl(123, component.validators);
expect(component.from.hasError('required')).toBe(false);
});
it('should throw error if "from" value is a negative value', () => {
component.ngOnInit();
component.from = new FormControl(-100, component.validators);
expect(component.from.hasError('min')).toBe(true);
});
});

View File

@ -55,7 +55,8 @@ export class SearchNumberRangeComponent implements SearchWidget, OnInit {
this.validators = Validators.compose([
Validators.required,
Validators.pattern(/^-?(0|[1-9]\d*)?$/)
Validators.pattern(/^-?(0|[1-9]\d*)?$/),
Validators.min(0)
]);
this.from = new FormControl('', this.validators);
@ -78,9 +79,8 @@ export class SearchNumberRangeComponent implements SearchWidget, OnInit {
map.set('TO', model.to);
const value = this.formatString(this.format, map);
const query = `${this.field}:${value}`;
this.context.queryFragments[this.id] = query;
this.context.queryFragments[this.id] = `${this.field}:${value}`;
this.context.update();
}
}