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

Allow empty value for Numeric masked input

3 Answers 1020 Views
MaskedInput (Numeric, DateTime, Text, Currency)
This is a migrated thread and some comments may be shown as answers.
Vikas
Top achievements
Rank 1
Vikas asked on 23 Jun 2016, 03:32 PM

I am using RadMaskedNumericInput, I have set the max and min and i have allow null to true, I want the users to be able to delete everything in the text box. But the first time user hit backspace it puts a zero in the text box, if i hit backspace again it will remove the zero.

is there i way to prevent the first zero.

And the interesting thing is that the binding value is set to null the first time i hit backspace, so the UI is 0 but the binding value is null, then when i hit backspace again to get rid of 0 the setter is never called.

Thanks

Vikas Mittal

 

<telerik:RadMaskedNumericInput Mask="" MaskedInput:MaskedInputExtensions.Maximum="99999999"
            TextMode="MaskedText" MaskedInput:MaskedInputExtensions.AllowNull="True" 
            Width="100" IsClearButtonVisible="False" Height="30" HorizontalAlignment="Center"
            MaskedInput:MaskedInputExtensions.Minimum="1"
            Style="{StaticResource SvtRadMaskedNumericInputStyle}" Value="{Binding Frequency, NotifyOnValidationError=True}"/>

3 Answers, 1 is accepted

Sort by
0
Vikas
Top achievements
Rank 1
answered on 23 Jun 2016, 04:20 PM

I was binding to a string property, I believe that was causing the zero issue even int? causes this, After binding to int property i am able to delete everything in the text box, but it brings up some other problems

- I have 1 in the textbox, after i hit backspace i can delete 1 but the setter is never called, UI shows empty but the binding value is 1. How can i know if the value is valid or not

- second issue is the moment i empty the text box I get the validation error with message value " can not be converted, is there a way to either prevent the validation from happening (I have my own validation which happens when user tries to close the window) or if we can not stop the validation from happening, is there a way to change the message I would like to provide a more meaning ful message

0
Vikas
Top achievements
Rank 1
answered on 23 Jun 2016, 04:30 PM
Setting to double? works.
0
Dinko | Tech Support Engineer
Telerik team
answered on 28 Jun 2016, 11:51 AM
Hello Vikas,

Thank you for contacting Telerik Support.

Let me first start with that value type of the RadMaskedNumericInput is designed to work with numbers and its Value property is of type Double? (nullable double) and when it is bound to nullable int there is no framework mechanism to automatically match the null from the set { null or int } to the null from the set {null or double}. That is why the of the bound property is not called when the value of the mask is null and the built-in validation error appears. In your case, you can change the type of the bound property to double? as you have already done (assuming from your last reply).

As for your second question you can change the validation error message to a custom one. We have Throwing Validation Exceptions help article in our documentation where you can find how to change the text of the error message. 

Regards,
Dinko
Telerik
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
Tags
MaskedInput (Numeric, DateTime, Text, Currency)
Asked by
Vikas
Top achievements
Rank 1
Answers by
Vikas
Top achievements
Rank 1
Dinko | Tech Support Engineer
Telerik team
Share this question
or