Allow empty value for Numeric masked input

4 posts, 0 answers
  1. Vikas
    Vikas avatar
    37 posts
    Member since:
    Dec 2015

    Posted 23 Jun 2016 Link to this post

    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.


    Vikas Mittal


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

  2. Vikas
    Vikas avatar
    37 posts
    Member since:
    Dec 2015

    Posted 23 Jun 2016 Link to this post

    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

  3. Vikas
    Vikas avatar
    37 posts
    Member since:
    Dec 2015

    Posted 23 Jun 2016 in reply to Vikas Link to this post

    Setting to double? works.
  4. Dinko
    Dinko avatar
    521 posts

    Posted 28 Jun 2016 Link to this post

    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 setter 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. 

    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
Back to Top