mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
fix: TextField not secure when keyboardType="number" (#5012)
This commit is contained in:
@@ -48,7 +48,7 @@ allTests["HTTP"] = httpTests;
|
|||||||
## Writing Test Module
|
## Writing Test Module
|
||||||
The test modules are actually TypeScript modules which export unit tests and hooks as functions following this convention:
|
The test modules are actually TypeScript modules which export unit tests and hooks as functions following this convention:
|
||||||
|
|
||||||
* All exported functions which with a `test` prefix are unit-tests.
|
* All exported functions with a `test` prefix are unit-tests.
|
||||||
* The `setUpModule()` hook is called once - before all the tests in the module.
|
* The `setUpModule()` hook is called once - before all the tests in the module.
|
||||||
* The `setUp()` hook is called before each tests.
|
* The `setUp()` hook is called before each tests.
|
||||||
* The `tearDown()` hook called after each tests.
|
* The `tearDown()` hook called after each tests.
|
||||||
|
|||||||
@@ -317,6 +317,32 @@ export var testSetSecure = function () {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export var testSetSecureAndKeyboardTypeNumber = function () {
|
||||||
|
helper.buildUIAndRunTest(_createTextFieldFunc(), function (views: Array<viewModule.View>) {
|
||||||
|
var textField = <textFieldModule.TextField>views[0];
|
||||||
|
|
||||||
|
textField.secure = true;
|
||||||
|
textField.keyboardType = "number";
|
||||||
|
|
||||||
|
var expectedValue = true;
|
||||||
|
var actualValue = textFieldTestsNative.getNativeSecure(textField);
|
||||||
|
TKUnit.assert(actualValue === expectedValue, "Actual: " + actualValue + "; Expected: " + expectedValue);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export var testSetKeyboardTypeNumberAndSecure = function () {
|
||||||
|
helper.buildUIAndRunTest(_createTextFieldFunc(), function (views: Array<viewModule.View>) {
|
||||||
|
var textField = <textFieldModule.TextField>views[0];
|
||||||
|
|
||||||
|
textField.keyboardType = "number";
|
||||||
|
textField.secure = true;
|
||||||
|
|
||||||
|
var expectedValue = true;
|
||||||
|
var actualValue = textFieldTestsNative.getNativeSecure(textField);
|
||||||
|
TKUnit.assert(actualValue === expectedValue, "Actual: " + actualValue + "; Expected: " + expectedValue);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
export var testBindSecureDirectlyToModel = function () {
|
export var testBindSecureDirectlyToModel = function () {
|
||||||
helper.buildUIAndRunTest(_createTextFieldFunc(), function (views: Array<viewModule.View>) {
|
helper.buildUIAndRunTest(_createTextFieldFunc(), function (views: Array<viewModule.View>) {
|
||||||
var textField = <textFieldModule.TextField>views[0];
|
var textField = <textFieldModule.TextField>views[0];
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { TextFieldBase, secureProperty, whiteSpaceProperty, WhiteSpace } from "./text-field-common";
|
import { TextFieldBase, secureProperty, whiteSpaceProperty, WhiteSpace, keyboardTypeProperty } from "./text-field-common";
|
||||||
|
|
||||||
export * from "./text-field-common";
|
export * from "./text-field-common";
|
||||||
|
|
||||||
@@ -14,13 +14,22 @@ export class TextField extends TextFieldBase {
|
|||||||
this.notify({ eventName: TextField.returnPressEvent, object: this })
|
this.notify({ eventName: TextField.returnPressEvent, object: this })
|
||||||
}
|
}
|
||||||
|
|
||||||
[secureProperty.setNative](value: boolean) {
|
[secureProperty.setNative]() {
|
||||||
|
this.setSecureAndKeyboardType();
|
||||||
|
}
|
||||||
|
|
||||||
|
[keyboardTypeProperty.setNative]() {
|
||||||
|
this.setSecureAndKeyboardType();
|
||||||
|
}
|
||||||
|
|
||||||
|
setSecureAndKeyboardType(): void {
|
||||||
|
|
||||||
let inputType: number;
|
let inputType: number;
|
||||||
|
|
||||||
// Password variations are supported only for Text and Number classes.
|
// Password variations are supported only for Text and Number classes.
|
||||||
if (value) {
|
if (this.secure) {
|
||||||
if (this.keyboardType === "number") {
|
if (this.keyboardType === "number") {
|
||||||
inputType = android.text.InputType.TYPE_CLASS_TEXT | android.text.InputType.TYPE_NUMBER_VARIATION_PASSWORD;
|
inputType = android.text.InputType.TYPE_CLASS_NUMBER | android.text.InputType.TYPE_NUMBER_VARIATION_PASSWORD;
|
||||||
} else {
|
} else {
|
||||||
inputType = android.text.InputType.TYPE_CLASS_TEXT | android.text.InputType.TYPE_TEXT_VARIATION_PASSWORD;
|
inputType = android.text.InputType.TYPE_CLASS_TEXT | android.text.InputType.TYPE_TEXT_VARIATION_PASSWORD;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user