MaskedNumericInput: Allow any decimal number

2 posts, 0 answers
  1. bitbonk
    bitbonk avatar
    10 posts
    Member since:
    Apr 2012

    Posted 11 Jun Link to this post

    How do I have to configure the RadMaskedNumericInput Control so that:

    1. the user can enter any decimal number with any precision, with or without a decimal separator, positive or negative 

    2. no mask placeholders or literals are visible (no _ and a the decimal separator only visible when the user actually entered one)

     

     

  2. Dinko
    Admin
    Dinko avatar
    1124 posts

    Posted 16 Jun Link to this post

    Hello Jim,

    Thank you for your interest in our RadMaskedInput controls.

    Upon reading your requirements, there is not a build-in set-up to achieve this. The struggle comes from the fact that the user can enter a different number of digits after the dot. So you will need to remove the Mask property and work with No Mask scenario. This way, you can't enter decimal dot separator as the control is not aware of how many numbers after the dot will be entered.

    <telerik:RadMaskedNumericInput Placeholder=" " Mask="" Height="30" Width="200" />

    What you can consider is using our RadMaskedTextInput control. The struggle here will be that you will need to handle the input which comes from the user. For example, you can subscribe to the PreviewKeyDown event of the control and check if the user enters numbers. If not, handle the event.  For example: 

    <telerik:RadMaskedTextInput  Mask=""  Height="30" Width="200" VerticalAlignment="Center" 
                                    PreviewKeyDown="RadMaskedTextInput_PreviewKeyDown" Placeholder=" "/>

    private void RadMaskedTextInput_PreviewKeyDown(object sender, KeyEventArgs e)
    {
        if( ! (e.Key == Key.D0 ||
            e.Key == Key.D1 || 
            e.Key == Key.D2 || 
            e.Key == Key.D3 || 
            e.Key == Key.D4 || 
            e.Key == Key.D5 || 
            e.Key == Key.D6 ||
            e.Key == Key.D7 ||
            e.Key == Key.D8 ||
            e.Key == Key.D9 ||
            e.Key == Key.OemPeriod
            ))
        {
            e.Handled = true;   
        }
    }

    The above code snippet will cover only one scenario. You will need to extend it so it covers all keyboard numbers (NumPad numbers). Also, handle the case when the user press dot again, etc. 

    Can you give the above suggestion a try and let me know if I have missed something from your scenario?

    Regards,
    Dinko
    Progress Telerik

    Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
    Our thoughts here at Progress are with those affected by the outbreak.
Back to Top