This is a migrated thread and some comments may be shown as answers.

Keyboard type with Masked Input

1 Answer 199 Views
MaskedInput
This is a migrated thread and some comments may be shown as answers.
Kyle
Top achievements
Rank 1
Kyle asked on 18 May 2018, 07:11 AM

Is there any way to set a keyboard type when using a Masked Input field? We are making use of it for some numeric-only fields, however I can't find any way to make the keyboard default to a numerical keyboard.

 

Even the example project has phone number input using the default text keyboard. Is there no way to set which keyboard type to use?

1 Answer, 1 is accepted

Sort by
0
Stefan Nenchev
Telerik team
answered on 22 May 2018, 01:47 PM
Hello, Kyle,

You can create custom renderers and set the keyboard types on the platform specific elements. For example:

Android:

[assembly: Xamarin.Forms.ExportRenderer(typeof(Telerik.XamarinForms.Input.MaskedInputElement), typeof(MyCustomMaskRenderer))]
namespace MaskInputKeyboard.Droid.CustomRenderer
{
    public class MyCustomMaskRenderer : MaskedInputRenderer
    {
        protected override void OnElementChanged(ElementChangedEventArgs<MaskedInputElement> e)
        {
            base.OnElementChanged(e);
            var inputType = this.Control.InputType;
            this.Control.SetRawInputType(Android.Text.InputTypes.ClassNumber);
        }
    }
}

iOS:

[assembly: Xamarin.Forms.ExportRenderer(typeof(Telerik.XamarinForms.Input.MaskedInputElement), typeof(MyCustomMaskRenderer))]
namespace MaskInputKeyboard.iOS.CustomMaskRenderer
{
    public class MyCustomMaskRenderer : MaskedInputRenderer
    {
        protected override void OnElementChanged(ElementChangedEventArgs<MaskedInputElement> e)
        {
            base.OnElementChanged(e);
            this.Control.KeyboardType = UIKeyboardType.DecimalPad;
        }
    }
}

I hope the information will be useful.

Have a great rest of the week.

Regards,
Stefan Nenchev
Progress Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
MaskedInput
Asked by
Kyle
Top achievements
Rank 1
Answers by
Stefan Nenchev
Telerik team
Share this question
or