Skip to content

Commit 3e6f465

Browse files
author
Vasil Chimev
authored
fix: TextField not secure when keyboardType="number" (#5012)
1 parent 32b9ec2 commit 3e6f465

3 files changed

Lines changed: 40 additions & 5 deletions

File tree

‎WritingUnitTests.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ allTests["HTTP"] = httpTests;
4848
## Writing Test Module
4949
The test modules are actually TypeScript modules which export unit tests and hooks as functions following this convention:
5050

51-
* All exported functions which with a `test` prefix are unit-tests.
51+
* All exported functions with a `test` prefix are unit-tests.
5252
* The `setUpModule()` hook is called once - before all the tests in the module.
5353
* The `setUp()` hook is called before each tests.
5454
* The `tearDown()` hook called after each tests.

‎tests/app/ui/text-field/text-field-tests.ts‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,32 @@ export var testSetSecure = function () {
317317
});
318318
}
319319

320+
export var testSetSecureAndKeyboardTypeNumber = function () {
321+
helper.buildUIAndRunTest(_createTextFieldFunc(), function (views: Array<viewModule.View>) {
322+
var textField = <textFieldModule.TextField>views[0];
323+
324+
textField.secure = true;
325+
textField.keyboardType = "number";
326+
327+
var expectedValue = true;
328+
var actualValue = textFieldTestsNative.getNativeSecure(textField);
329+
TKUnit.assert(actualValue === expectedValue, "Actual: " + actualValue + "; Expected: " + expectedValue);
330+
});
331+
}
332+
333+
export var testSetKeyboardTypeNumberAndSecure = function () {
334+
helper.buildUIAndRunTest(_createTextFieldFunc(), function (views: Array<viewModule.View>) {
335+
var textField = <textFieldModule.TextField>views[0];
336+
337+
textField.keyboardType = "number";
338+
textField.secure = true;
339+
340+
var expectedValue = true;
341+
var actualValue = textFieldTestsNative.getNativeSecure(textField);
342+
TKUnit.assert(actualValue === expectedValue, "Actual: " + actualValue + "; Expected: " + expectedValue);
343+
});
344+
}
345+
320346
export var testBindSecureDirectlyToModel = function () {
321347
helper.buildUIAndRunTest(_createTextFieldFunc(), function (views: Array<viewModule.View>) {
322348
var textField = <textFieldModule.TextField>views[0];

‎tns-core-modules/ui/text-field/text-field.android.ts‎

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { TextFieldBase, secureProperty, whiteSpaceProperty, WhiteSpace } from "./text-field-common";
1+
import { TextFieldBase, secureProperty, whiteSpaceProperty, WhiteSpace, keyboardTypeProperty } from "./text-field-common";
22

33
export * from "./text-field-common";
44

@@ -14,13 +14,22 @@ export class TextField extends TextFieldBase {
1414
this.notify({ eventName: TextField.returnPressEvent, object: this })
1515
}
1616

17-
[secureProperty.setNative](value: boolean) {
17+
[secureProperty.setNative]() {
18+
this.setSecureAndKeyboardType();
19+
}
20+
21+
[keyboardTypeProperty.setNative]() {
22+
this.setSecureAndKeyboardType();
23+
}
24+
25+
setSecureAndKeyboardType(): void {
26+
1827
let inputType: number;
1928

2029
// Password variations are supported only for Text and Number classes.
21-
if (value) {
30+
if (this.secure) {
2231
if (this.keyboardType === "number") {
23-
inputType = android.text.InputType.TYPE_CLASS_TEXT | android.text.InputType.TYPE_NUMBER_VARIATION_PASSWORD;
32+
inputType = android.text.InputType.TYPE_CLASS_NUMBER | android.text.InputType.TYPE_NUMBER_VARIATION_PASSWORD;
2433
} else {
2534
inputType = android.text.InputType.TYPE_CLASS_TEXT | android.text.InputType.TYPE_TEXT_VARIATION_PASSWORD;
2635
}

0 commit comments

Comments
 (0)