TommyDawkins
Topic Author
Posts: 4
Joined: 16 Apr 2024, 18:36

Unity Android Textbox Autofill / Autocomplete | Need to disable AutoFill for textbox (Android project)

16 Apr 2024, 18:41

Hello People,

Right now, I need to use the android keyboard when I press a textbox to enter text. It open the android keyboard. The thing is, I want to disable autocomplete/Autofill so the text I just entered will not be save a autocomplete possibility on a next textbox. Is there a way to do it? I tried InputScope="Password" but everything I typed in this textbox is still save in autocomplete possibility.

Thanks,
Tommy
 
User avatar
jsantos
Site Admin
Posts: 3931
Joined: 20 Jan 2012, 17:18
Contact:

Re: Unity Android Textbox Autofill / Autocomplete | Need to disable AutoFill for textbox (Android project)

17 Apr 2024, 12:10

We are using Unity TouchScreenKeyboard.Open for opening the keyboard. How would achieve what you want with that API?

If you find a way, you can modify NoesisUnity.cs (line 509)
#if UNITY_2018_1_OR_NEWER
  keyboard_ = TouchScreenKeyboard.Open(text, keyboardType, true, multiline, secure, false, "", characterLimit);
#else
  keyboard_ = TouchScreenKeyboard.Open(text, keyboardType, true, multiline, secure, false, "");
#endif
If your solution works we can officially apply this change.
 
TommyDawkins
Topic Author
Posts: 4
Joined: 16 Apr 2024, 18:36

Re: Unity Android Textbox Autofill / Autocomplete | Need to disable AutoFill for textbox (Android project)

17 Apr 2024, 21:09

Here's what I'll update and test but need to embedded noesis package so my code isn't overwrite. Don't know if you could test it from you side faster than me.
        public static void Open(UIElement focused_)
        {
            string text = "";
            TouchScreenKeyboardType keyboardType = TouchScreenKeyboardType.Default;
            bool multiline = false;
            bool autoCorrection = true;
            bool secure = false;
            int characterLimit = 0;
            FrameworkElement focusedInputScopeElement = null;

            if (focused_ is FrameworkElement)
            {
                focusedInputScopeElement = (FrameworkElement)focused_;
		switch (focusedInputScopeElement.InputScope)
                {
                    case InputScope.Url:
                        keyboardType = TouchScreenKeyboardType.URL;
                        break;
                    case InputScope.Digits:
                    case InputScope.Number:
                    case InputScope.NumberFullWidth:
                        keyboardType = TouchScreenKeyboardType.NumbersAndPunctuation;
                        break;
                    case InputScope.TelephoneNumber:
                    case InputScope.TelephoneLocalNumber:
                        keyboardType = TouchScreenKeyboardType.PhonePad;
                        break;
                    case InputScope.AlphanumericFullWidth:
                    case InputScope.AlphanumericHalfWidth:
                        keyboardType = TouchScreenKeyboardType.NamePhonePad;
                        break;
                    case InputScope.EmailSmtpAddress:
                        keyboardType = TouchScreenKeyboardType.EmailAddress;
                        break;
                    case InputScope.RegularExpression:
                        keyboardType = TouchScreenKeyboardType.Search;
                        break;
                    default:
                        keyboardType = TouchScreenKeyboardType.Default;
                        break;
                }
            }

            TextBox textBox = focused_ as TextBox;
            PasswordBox passwordBox = focused_ as PasswordBox;

            if (textBox != null)
            {
                text = textBox.Text;
                multiline = textBox.TextWrapping == TextWrapping.Wrap && textBox.AcceptsReturn;
                characterLimit = textBox.MaxLength;

                // Use Password Input Scope with  textbox to show or not Autocomplete
                if (focusedInputScopeElement != null)
                {
                    autoCorrection = focusedInputScopeElement.InputScope != InputScope.Password;
                }
            }
            else if (passwordBox != null)
            {
                text = passwordBox.Password;
                secure = true;
            }

            TouchScreenKeyboard keyboard_;

          #if UNITY_2018_1_OR_NEWER
            keyboard_ = TouchScreenKeyboard.Open(text, keyboardType, autoCorrection, multiline, secure, false, "", characterLimit);
#else
            keyboard_ = TouchScreenKeyboard.Open(text, keyboardType, autoCorrection, multiline, secure, false, "");
#endif

            if (keyboard_.status == TouchScreenKeyboard.Status.Visible)
            {
                if (textBox != null)
                {
                    textBox.HideCaret();
                }
                else if (passwordBox != null)
                {
                    passwordBox.HideCaret();
                }

                keyboard = keyboard_;
                focused = focused_;
                undoString = text;
            }
        }
 
TommyDawkins
Topic Author
Posts: 4
Joined: 16 Apr 2024, 18:36

Re: Unity Android Textbox Autofill / Autocomplete | Need to disable AutoFill for textbox (Android project)

17 Apr 2024, 23:43

Update: Just tested what I posted and setting Autocorrection to false when opening android soft keyboard on textbox click don't seems to hide the suggestion bar.

Update No2: It look like the suggestion bar is still there BUT, it don't save word that we enter in textbox so good for me.

Question: Is it possible for you to add a property about autoComplete On textbox so we can manage it?
 
User avatar
jsantos
Site Admin
Posts: 3931
Joined: 20 Jan 2012, 17:18
Contact:

Re: Unity Android Textbox Autofill / Autocomplete | Need to disable AutoFill for textbox (Android project)

22 Apr 2024, 15:50

We could also use one of the InputScopes for this (like Private). Would this a valid solution for you?

Could you please create a ticket for this?
 
 

Who is online

Users browsing this forum: Bing [Bot], Google [Bot], hcpizzi, Semrush [Bot] and 10 guests