mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
fix(android): KeyboardType now respects numbers (#9240)
This commit is contained in:
committed by
GitHub
parent
c04e1b59e5
commit
f08fcb17b4
@@ -1546,12 +1546,18 @@ export function makeValidator<T>(...values: T[]): (value: any) => value is T {
|
||||
return (value: any): value is T => set.has(value);
|
||||
}
|
||||
|
||||
export function makeParser<T>(isValid: (value: any) => boolean): (value: any) => T {
|
||||
export function makeParser<T>(isValid: (value: any) => boolean, allowNumbers = false): (value: any) => T {
|
||||
return (value) => {
|
||||
const lower = value && value.toLowerCase();
|
||||
if (isValid(lower)) {
|
||||
return lower;
|
||||
} else {
|
||||
if (allowNumbers) {
|
||||
const convNumber = +value;
|
||||
if (!isNaN(convNumber)) {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
throw new Error('Invalid value: ' + value);
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user