Skip to content

Commit

Permalink
Add function to toggle show/hide password. Update jquery selectors to…
Browse files Browse the repository at this point in the history
… use IDs instead of type selectors.

Selectors need to be changed due to the password field being toggled 
between "password" and "text", which would make it impossible to access 
the password input while the password is shown.
  • Loading branch information
tobiv committed Jan 26, 2021
1 parent 5a941c4 commit a05e79e
Showing 1 changed file with 32 additions and 20 deletions.
52 changes: 32 additions & 20 deletions Beocreate2/beo-views/default/scripts/beo-ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -1927,36 +1927,36 @@ function startTextInput(type, title, prompt, options, callback, cancelCallback)

if (options.autocapitalise) {
if (options.autocapitalise == true) {
$("#text-input input[type=text]").attr("autocapitalize", "sentences");
$("#text-input-plain").attr("autocapitalize", "sentences");
} else {
$("#text-input input[type=text]").attr("autocapitalize", options.autocapitalise);
$("#text-input-plain").attr("autocapitalize", options.autocapitalise);
}
} else {
$("#text-input input[type=text]").attr("autocapitalize", "off");
$("#text-input-plain").attr("autocapitalize", "off");
}

if (options.autocorrect) {
$("#text-input input[type=text]").attr("autocorrect", "on");
$("#text-input-plain").attr("autocorrect", "on");
} else {
$("#text-input input[type=text]").attr("autocorrect", "off");
$("#text-input-plain").attr("autocorrect", "off");
}
$("#text-input input[type=password]").attr("placeholder", "");
$("#text-input input[type=text]").attr("placeholder", "");
if (options.placeholders.text) $("#text-input input[type=text]").attr("placeholder", options.placeholders.text);
if (options.placeholders.password) $("#text-input input[type=password]").attr("placeholder", options.placeholders.password);
$("#text-input-password").attr("placeholder", "");
$("#text-input-plain").attr("placeholder", "");
if (options.placeholders.text) $("#text-input-plain").attr("placeholder", options.placeholders.text);
if (options.placeholders.password) $("#text-input-password").attr("placeholder", options.placeholders.password);

$("#text-input input[type=text], #text-input input[type=password]").val("");
if (options.text) $("#text-input input[type=text]").val(options.text);
$("#text-input-plain, #text-input-password").val("");
if (options.text) $("#text-input-plain").val(options.text);

$("#text-prompt").text(prompt);
$("#text-input h1").text(title);
textInputCallback = callback;

//setTimeout(function() {
if (type == 2) {
$("#text-input input[type=password]").focus();
$("#text-input-password").focus();
} else {
$("#text-input input[type=text]").focus();
$("#text-input-plain").focus();
}
//}, 600);
validateTextInput();
Expand All @@ -1966,8 +1966,8 @@ function startTextInput(type, title, prompt, options, callback, cancelCallback)
var textInputValid = false;
function validateTextInput() {
textInputValid = true;
txt = $("#text-input input[type=text]").val();
passwd = $("#text-input input[type=password]").val();
txt = $("#text-input-plain").val();
passwd = $("#text-input-password").val();
if (textInputMode == 1 || textInputMode == 3) {
if (!txt) {
if (textInputOptions.optional && textInputOptions.optional.text) {
Expand Down Expand Up @@ -1999,10 +1999,21 @@ function validateTextInput() {
}
}

function togglePasswordReveal() {
var fieldType = "password" // default

if($("#text-input-password").prop("type") == "password") {
fieldType = "text";
}

$("#text-input-password").prop("type", fieldType);
$("#text-input-password").focus();
}

function submitText() {
if (textInputValid) {
txt = $("#text-input input[type=text]").val();
passwd = $("#text-input input[type=password]").val();
txt = $("#text-input-plain").val();
passwd = $("#text-input-password").val();
cancelText(true);
textInputCallback({text: txt, password: passwd});
return true;
Expand All @@ -2013,12 +2024,12 @@ function submitText() {


function cancelText(hideOnly) {
$("#text-input input[type=text], #text-input input[type=password]").blur();
$("#text-input-plain, #text-input-password").blur();
$("#text-input, #text-input-back-plate").removeClass("visible");
textInputCloseTimeout = setTimeout(function() {
$("#text-input, #text-input-back-plate").removeClass("block");
$("#text-input input[type=text]").val("");
$("#text-input input[type=password]").val("");
$("#text-input-plain").val("");
$("#text-input-password").val("");
}, 500);
if (!hideOnly) {
textInputCallback();
Expand Down Expand Up @@ -2319,6 +2330,7 @@ return {
hidePopupView: hidePopupView,
popupBackplateClick: popupBackplateClick,
startTextInput: startTextInput,
togglePasswordReveal: togglePasswordReveal,
submitText: submitText,
cancelText: cancelText,
uploadFile: uploadFile,
Expand Down

0 comments on commit a05e79e

Please sign in to comment.