diff --git a/WritingUnitTests.md b/WritingUnitTests.md index 5b99b7b7c..22faaa8bf 100644 --- a/WritingUnitTests.md +++ b/WritingUnitTests.md @@ -48,7 +48,7 @@ allTests["HTTP"] = httpTests; ## Writing Test Module 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 `setUp()` hook is called before each tests. * The `tearDown()` hook called after each tests. diff --git a/tests/app/ui/text-field/text-field-tests.ts b/tests/app/ui/text-field/text-field-tests.ts index adfc52309..fcd0ad2e7 100644 --- a/tests/app/ui/text-field/text-field-tests.ts +++ b/tests/app/ui/text-field/text-field-tests.ts @@ -317,6 +317,32 @@ export var testSetSecure = function () { }); } +export var testSetSecureAndKeyboardTypeNumber = function () { + helper.buildUIAndRunTest(_createTextFieldFunc(), function (views: Array) { + var 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) { + var 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 () { helper.buildUIAndRunTest(_createTextFieldFunc(), function (views: Array) { var textField = views[0]; diff --git a/tns-core-modules/ui/text-field/text-field.android.ts b/tns-core-modules/ui/text-field/text-field.android.ts index 92a627736..16920c6c2 100644 --- a/tns-core-modules/ui/text-field/text-field.android.ts +++ b/tns-core-modules/ui/text-field/text-field.android.ts @@ -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"; @@ -14,13 +14,22 @@ export class TextField extends TextFieldBase { this.notify({ eventName: TextField.returnPressEvent, object: this }) } - [secureProperty.setNative](value: boolean) { + [secureProperty.setNative]() { + this.setSecureAndKeyboardType(); + } + + [keyboardTypeProperty.setNative]() { + this.setSecureAndKeyboardType(); + } + + setSecureAndKeyboardType(): void { + let inputType: number; // Password variations are supported only for Text and Number classes. - if (value) { + if (this.secure) { 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 { inputType = android.text.InputType.TYPE_CLASS_TEXT | android.text.InputType.TYPE_TEXT_VARIATION_PASSWORD; }