mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-10-30 23:47:18 +08:00
feat(TextField): decimal keyboardType (#10789)
This commit is contained in:
@ -339,6 +339,32 @@ export var testSetKeyboardTypeNumberAndSecure = function () {
|
||||
});
|
||||
};
|
||||
|
||||
export var testSetSecureAndKeyboardTypeDecimal = function () {
|
||||
helper.buildUIAndRunTest(_createTextFieldFunc(), function (views: Array<View>) {
|
||||
var textField = <TextField>views[0];
|
||||
|
||||
textField.secure = true;
|
||||
textField.keyboardType = 'decimal';
|
||||
|
||||
var expectedValue = true;
|
||||
var actualValue = getNativeSecure(textField);
|
||||
TKUnit.assert(actualValue === expectedValue, 'Actual: ' + actualValue + '; Expected: ' + expectedValue);
|
||||
});
|
||||
};
|
||||
|
||||
export var testSetKeyboardTypeDecimalAndSecure = function () {
|
||||
helper.buildUIAndRunTest(_createTextFieldFunc(), function (views: Array<View>) {
|
||||
var textField = <TextField>views[0];
|
||||
|
||||
textField.keyboardType = 'decimal';
|
||||
textField.secure = true;
|
||||
|
||||
var expectedValue = true;
|
||||
var actualValue = getNativeSecure(textField);
|
||||
TKUnit.assert(actualValue === expectedValue, 'Actual: ' + actualValue + '; Expected: ' + expectedValue);
|
||||
});
|
||||
};
|
||||
|
||||
export var testBindSecureDirectlyToModel = function () {
|
||||
helper.buildUIAndRunTest(_createTextFieldFunc(), function (views: Array<View>) {
|
||||
var textField = <TextField>views[0];
|
||||
|
||||
@ -40,11 +40,12 @@ export namespace CoreTypes {
|
||||
unit: 'px',
|
||||
};
|
||||
|
||||
export type KeyboardInputType = 'datetime' | 'phone' | 'number' | 'url' | 'email' | 'integer';
|
||||
export type KeyboardInputType = 'datetime' | 'phone' | 'number' | 'decimal' | 'url' | 'email' | 'integer';
|
||||
export namespace KeyboardType {
|
||||
export const datetime = 'datetime';
|
||||
export const phone = 'phone';
|
||||
export const number = 'number';
|
||||
export const decimal = 'decimal';
|
||||
export const url = 'url';
|
||||
export const email = 'email';
|
||||
export const integer = 'integer';
|
||||
|
||||
@ -67,7 +67,7 @@ export const placeholderColorProperty = new CssProperty<Style, Color>({
|
||||
});
|
||||
placeholderColorProperty.register(Style);
|
||||
|
||||
const keyboardTypeConverter = makeParser<CoreTypes.KeyboardInputType>(makeValidator<CoreTypes.KeyboardInputType>(CoreTypes.KeyboardType.datetime, CoreTypes.KeyboardType.phone, CoreTypes.KeyboardType.number, CoreTypes.KeyboardType.url, CoreTypes.KeyboardType.email, CoreTypes.KeyboardType.integer), true);
|
||||
const keyboardTypeConverter = makeParser<CoreTypes.KeyboardInputType>(makeValidator<CoreTypes.KeyboardInputType>(CoreTypes.KeyboardType.datetime, CoreTypes.KeyboardType.phone, CoreTypes.KeyboardType.number, CoreTypes.KeyboardType.decimal, CoreTypes.KeyboardType.url, CoreTypes.KeyboardType.email, CoreTypes.KeyboardType.integer), true);
|
||||
|
||||
export const autofillTypeProperty = new Property<EditableTextBase, CoreTypes.AutofillType>({ name: 'autofillType' });
|
||||
autofillTypeProperty.register(EditableTextBase);
|
||||
|
||||
@ -204,7 +204,7 @@ export abstract class EditableTextBase extends EditableTextBaseCommon {
|
||||
[keyboardTypeProperty.getDefault](): number {
|
||||
return this.nativeTextViewProtected.getInputType();
|
||||
}
|
||||
[keyboardTypeProperty.setNative](value: 'datetime' | 'phone' | 'number' | 'url' | 'email' | 'integer' | number) {
|
||||
[keyboardTypeProperty.setNative](value: 'datetime' | 'phone' | 'number' | 'decimal' | 'url' | 'email' | 'integer' | number) {
|
||||
let newInputType;
|
||||
|
||||
switch (value) {
|
||||
@ -220,6 +220,10 @@ export abstract class EditableTextBase extends EditableTextBaseCommon {
|
||||
newInputType = android.text.InputType.TYPE_CLASS_NUMBER | android.text.InputType.TYPE_NUMBER_VARIATION_NORMAL | android.text.InputType.TYPE_NUMBER_FLAG_SIGNED | android.text.InputType.TYPE_NUMBER_FLAG_DECIMAL;
|
||||
break;
|
||||
|
||||
case 'decimal':
|
||||
newInputType = android.text.InputType.TYPE_CLASS_NUMBER | android.text.InputType.TYPE_NUMBER_FLAG_DECIMAL | android.text.InputType.TYPE_NUMBER_FLAG_SIGNED;
|
||||
break;
|
||||
|
||||
case 'url':
|
||||
newInputType = android.text.InputType.TYPE_CLASS_TEXT | android.text.InputType.TYPE_TEXT_VARIATION_URI;
|
||||
break;
|
||||
|
||||
@ -34,7 +34,7 @@ export abstract class EditableTextBase extends EditableTextBaseCommon {
|
||||
return keyboardType.toString();
|
||||
}
|
||||
}
|
||||
[keyboardTypeProperty.setNative](value: 'datetime' | 'phone' | 'number' | 'url' | 'email' | 'integer' | string) {
|
||||
[keyboardTypeProperty.setNative](value: 'datetime' | 'phone' | 'number' | 'decimal' | 'url' | 'email' | 'integer' | string) {
|
||||
let newKeyboardType: UIKeyboardType;
|
||||
switch (value) {
|
||||
case 'datetime':
|
||||
@ -49,6 +49,10 @@ export abstract class EditableTextBase extends EditableTextBaseCommon {
|
||||
newKeyboardType = UIKeyboardType.NumbersAndPunctuation;
|
||||
break;
|
||||
|
||||
case 'decimal':
|
||||
newKeyboardType = UIKeyboardType.DecimalPad;
|
||||
break;
|
||||
|
||||
case 'url':
|
||||
newKeyboardType = UIKeyboardType.URL;
|
||||
break;
|
||||
|
||||
@ -78,6 +78,9 @@ export class TextField extends TextFieldBase {
|
||||
case 'number':
|
||||
inputType = android.text.InputType.TYPE_CLASS_NUMBER | android.text.InputType.TYPE_NUMBER_VARIATION_NORMAL | android.text.InputType.TYPE_NUMBER_FLAG_SIGNED | android.text.InputType.TYPE_NUMBER_FLAG_DECIMAL;
|
||||
break;
|
||||
case 'decimal':
|
||||
inputType = android.text.InputType.TYPE_CLASS_NUMBER | android.text.InputType.TYPE_NUMBER_FLAG_DECIMAL | android.text.InputType.TYPE_NUMBER_FLAG_SIGNED;
|
||||
break;
|
||||
case 'url':
|
||||
inputType = android.text.InputType.TYPE_CLASS_TEXT | android.text.InputType.TYPE_TEXT_VARIATION_URI;
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user