[ADF-2916] number range form validator added (#3279)

* number range form validator added

* tests added
This commit is contained in:
bbcodrin 2018-05-10 12:12:40 +03:00 committed by Eugenio Romano
parent d361c7ddd8
commit a5aff3d2df
2 changed files with 17 additions and 1 deletions

View File

@ -16,6 +16,7 @@
*/ */
import { SearchNumberRangeComponent } from './search-number-range.component'; import { SearchNumberRangeComponent } from './search-number-range.component';
import { FormControl, FormGroup } from '@angular/forms';
describe('SearchNumberRangeComponent', () => { describe('SearchNumberRangeComponent', () => {
@ -124,4 +125,15 @@ describe('SearchNumberRangeComponent', () => {
expect(context.queryFragments['range1']).toEqual('cm:content.size:<0 TO 100>'); expect(context.queryFragments['range1']).toEqual('cm:content.size:<0 TO 100>');
}); });
it('should return true if TO value is bigger than FROM value', () => {
component.ngOnInit();
component.from = new FormControl('10');
component.to = new FormControl('20');
component.form = new FormGroup({
from: component.from,
to: component.to
}, component.formValidator);
expect(component.formValidator).toBeTruthy();
});
}); });

View File

@ -62,7 +62,11 @@ export class SearchNumberRangeComponent implements SearchWidget, OnInit {
this.form = new FormGroup({ this.form = new FormGroup({
from: this.from, from: this.from,
to: this.to to: this.to
}); }, this.formValidator);
}
formValidator(formGroup: FormGroup) {
return parseInt(formGroup.get('from').value, 10) < parseInt(formGroup.get('to').value, 10) ? null : {'mismatch': true};
} }
apply(model: { from: string, to: string }, isValid: boolean) { apply(model: { from: string, to: string }, isValid: boolean) {