locked
Change Entry keyboard type while typing RRS feed

  • Question

  • User79778 posted

    I'm trying to change the keyboard-type of an Entry while the user is typing. The thing is, I want it to change to numeric keyboard if the text is 3 characters or more. Inside "OnTextChanged" if (_entry.Text.Length >= 3) { _entry.Keyboard = Keyboard.Numeric; }

    This works fine on Android, but not on iOS or Win Phone. Setting keyboard type on WinPhone and iOS only works if the keyboard type is set from start.

    Could someone confirm this? Should it be like this? Regards Andreas

    Tuesday, June 16, 2015 7:07 AM

Answers

  • User19820 posted

    I confirm it for iOS, it's a bug. But it's very easy to fix, just add your own Entry renderer

    public class EntryRenderer : Xamarin.Forms.Platform.iOS.EntryRenderer
    {
            protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
            {
                   base.OnElementPropertyChanged(sender, e);
                   if (e.PropertyName == InputView.KeyboardProperty.PropertyName)
                   {
                       this.UpdateKeyboard();
                   }
            }
    
           void UpdateKeyboard()
           {
                   Control.ReloadInputViews();
           }
    }
    

    Hope this helps

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Tuesday, June 16, 2015 7:37 AM
  • User19820 posted

    seems like a limitation of the WinPhone platform changing the InputScope of a TextBox has no effect. Not even if you disable and then enable the control. try to find that first and then come back to your Xamarin Forms app and do it with a renderer for WinPhone

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Tuesday, June 16, 2015 9:19 AM

All replies

  • User19820 posted

    I confirm it for iOS, it's a bug. But it's very easy to fix, just add your own Entry renderer

    public class EntryRenderer : Xamarin.Forms.Platform.iOS.EntryRenderer
    {
            protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
            {
                   base.OnElementPropertyChanged(sender, e);
                   if (e.PropertyName == InputView.KeyboardProperty.PropertyName)
                   {
                       this.UpdateKeyboard();
                   }
            }
    
           void UpdateKeyboard()
           {
                   Control.ReloadInputViews();
           }
    }
    

    Hope this helps

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Tuesday, June 16, 2015 7:37 AM
  • User19820 posted

    on WinPhone, it's probably a similar thing, not sure

    Tuesday, June 16, 2015 7:55 AM
  • User79778 posted

    Well, that solved it for iOS, but I havn't been able to do the same for WinPhone =(

    Tuesday, June 16, 2015 8:35 AM
  • User19820 posted

    seems like a limitation of the WinPhone platform changing the InputScope of a TextBox has no effect. Not even if you disable and then enable the control. try to find that first and then come back to your Xamarin Forms app and do it with a renderer for WinPhone

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Tuesday, June 16, 2015 9:19 AM
  • User79778 posted

    I Think you are correct. Seems like a limitation on WinPhone. Can't do it in a Clean WP Project either. Thanks for your help!

    Btw, do you know a way of showing the "Numbers and symbols" variation (123?) of the text-keyboard för Android?

    Tuesday, June 16, 2015 10:17 AM
  • User19820 posted

    just to be sure I understand, "Numbers and symbols" is something you don't have in Xamarin Forms right?

    Tuesday, June 16, 2015 10:20 AM
  • User79778 posted

    Exactly. Have to be done in a native renderer i Think. On iOS it is called "NumbersAndPunctuation"

    Tuesday, June 16, 2015 10:24 AM
  • User19820 posted

    if you must do this on WinPhone it would be harder (due to how Entry is implemented on WinPhone) for iOS and Android not sure, but I think it's easier

    Tuesday, June 16, 2015 10:40 AM
  • User149548 posted

    Is this fixed in the latest version?

    Wednesday, October 12, 2016 7:24 PM
  • User181025 posted

    @KingChrisCole I submitted a PR to fix it: https://github.com/xamarin/Xamarin.Forms/pull/443

    Thursday, October 13, 2016 3:31 AM