[AAE-485] Fix card view int item validator when value is empty (#5205)

* [AAE-485] Fix card view int item validator when value is empty

* Avoid creating a function every time we validate number

* Add return type to method
This commit is contained in:
davidcanonieto
2019-11-08 14:06:22 +00:00
committed by Eugenio Romano
parent f0ac4b19ad
commit 2a76b0846d
3 changed files with 11 additions and 3 deletions

View File

@@ -22,6 +22,8 @@ export class CardViewItemFloatValidator implements CardViewItemValidator {
message = 'CORE.CARDVIEW.VALIDATORS.FLOAT_VALIDATION_ERROR';
isValid(value: any): boolean {
return !isNaN(parseFloat(value)) && isFinite(value);
return value === ''
|| !isNaN(parseFloat(value))
&& isFinite(value);
}
}

View File

@@ -22,6 +22,13 @@ export class CardViewItemIntValidator implements CardViewItemValidator {
message = 'CORE.CARDVIEW.VALIDATORS.INT_VALIDATION_ERROR';
isValid(value: any): boolean {
return !isNaN(value) && (function(x) { return (x | 0) === x; })(parseFloat(value));
return value === ''
|| !isNaN(value)
&& this.isIntegerNumber(value);
}
isIntegerNumber(value: any): boolean {
const parsedNumber = parseFloat(value);
return (parsedNumber | 0) === parsedNumber;
}
}