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

MaskedNumericInput: Allow any decimal number

3 Answers 711 Views
MaskedInput (Numeric, DateTime, Text, Currency)
This is a migrated thread and some comments may be shown as answers.
bitbonk
Top achievements
Rank 1
bitbonk asked on 11 Jun 2020, 03:27 PM

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)

 

 

3 Answers, 1 is accepted

Sort by
0
Dinko | Tech Support Engineer
Telerik team
answered on 16 Jun 2020, 08:59 AM

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.
0
Rob A.
Top achievements
Rank 2
Iron
Iron
Veteran
answered on 05 Jan 2021, 05:12 PM

I have this exact same requirement, it's a shame your controls can't handle this usage case.  Could this feature request please be added to any future update/release?  Most other 3rd party control vendors do allow for this usage case.

Cheers, Rob.

0
Dinko | Tech Support Engineer
Telerik team
answered on 08 Jan 2021, 12:02 PM

Hi Robin,

The RadMaskedNumericInput does not support entering values in scientific (exponent) format. A Feature Request regarding this is already logged in our Feedback Portal. I apologize for missing this in my first post. You can vote for its implementation to increase its priority.

If you want to have a dynamic format you can take a look at the Dynamic format string SDK example where you can see how you can change the FormatString property runtime. This way the user can enter a valid double value without restriction in the number of digits on both sides of the decimal point. Also, you can download our SDK Sample Browser where you can find the mentioned project.

Regards,
Dinko
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products, quickly just got a fresh new look + new and improved content, including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
MaskedInput (Numeric, DateTime, Text, Currency)
Asked by
bitbonk
Top achievements
Rank 1
Answers by
Dinko | Tech Support Engineer
Telerik team
Rob A.
Top achievements
Rank 2
Iron
Iron
Veteran
Share this question
or