- Home /
How to make a login screen without input bar and without having to press enter on password field?
Hi, I am really struggling with this because of the behavior of the PasswordField
component that won't let me retrieve the string if the user doesn't press done on the mobile keyboard.
Basically I need the PasswordField
to behave like the Textfield
component so that when the user touches the login Button
my app can directly send both fields even if the user hasn't pressed done on the mobile keyboard.
Is there any way to make this happen ?
Edit : Right now I have this code which works fine in the editor but no on mobile
public class Textfield : SquaredMenuElement, IMenuElement {
public string defaultText = "";
public bool isPasswordField = false;
public static bool inputHidden = true;
public GUIStyle style = new GUIStyle();
public static Dictionary<string, string> textValues = new Dictionary<string, string> ();
private string stringToEdit;
protected override void Awake(){
base.Awake ();
stringToEdit = defaultText;
TouchScreenKeyboard.hideInput = inputHidden;
}
void Update(){
Debug.Log( gameObject.name + " : " + stringToEdit + " focus : " + GUI.GetNameOfFocusedControl() );
}
void OnGUI(){
if(!isPasswordField){
GUI.SetNextControlName(gameObject.name);
stringToEdit = GUI.TextField ( position, stringToEdit, style);
} else {
GUI.SetNextControlName(gameObject.name);
stringToEdit = GUI.PasswordField( position, stringToEdit, '*', style);
}
if(GUI.GetNameOfFocusedControl() == gameObject.name && stringToEdit == defaultText){
stringToEdit = "";
}
}
public string GetText(){
return stringToEdit;
}
}
The problem is, on mobile (android at least, didn't try ios), when I have two of my custom Textfield
, whenever one gets the focus the value of the other is copied into it for some reason. Also this doesn't happen if you comment the line TouchScreenKeyboard.hideInput = inputHidden;
I'm only asking the below since you state:
The problem is, on mobile (android at least, didn't try ios), when I have two of my custom Textfield, whenever one gets the focus the value of the other is copied into it for some reason.
The above script, do you use it once for the controls? If you do, don't use a reference object (stringToEdit) for both fields since it points to the same object. If you don't, there is likely a bug, since it's not static (stringToEdit), the reference should be different if you use two instantiated objects that are of this type.
I do use the same prefab for my textfields but they have their own instances in the scene, the hierarchy is like this : Interface -> Login$$anonymous$$enu -> ( LoginField, PasswordField, LoginButton )
I suspect the problem comes from the keyboard which seems to become static ins$$anonymous$$d of per field when you use Touchscreen$$anonymous$$eyboard.hideinput
Your answer
Follow this Question
Related Questions
Creating a Password Field 1 Answer
why can I not log in using my email and password? 2 Answers
Gui Login With Interface 1 Answer
How to make a Keypad for a locked door 2 Answers
Checking a hash with random salt 2 Answers