mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-05-12 17:04:57 +00:00
[ADF-2916] number range form validator added (#3279)
* number range form validator added * tests added
This commit is contained in:
parent
d361c7ddd8
commit
a5aff3d2df
@ -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();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@ -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) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user