How to set value =0 when clear value of RadMaskCurrencyInput ?

10 posts, 0 answers
  1. Umbala
    Umbala avatar
    28 posts
    Member since:
    Mar 2010

    Posted 10 Apr 2011 Link to this post

    Hi telerik team!
    How to set value =0 when clear value of RadMaskCurrencyInput ? (now it return nothing)
    cases : 
        click button clear value : resolved
        Hold back key : ?
        Hold delete key: ?
    thanks!
  2. Alex Fidanov
    Admin
    Alex Fidanov avatar
    636 posts

    Posted 11 Apr 2011 Link to this post

    Hello Umbala,

    You can handle the ValueChanged event and set the value to zero, if the new value is null:

    private void RadMaskedNumericInput_ValueChanged(object sender, Telerik.Windows.RadRoutedEventArgs e)
    {
        if ((sender as RadMaskedNumericInput).Value == null)
        {
            (sender as RadMaskedNumericInput).Value = 0;
        }
    }

    Kind regards,
    Alex Fidanov
    the Telerik team
    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 Public Issue Tracking system and vote to affect the priority of the items
  3. DevCraft banner
  4. Umbala
    Umbala avatar
    28 posts
    Member since:
    Mar 2010

    Posted 14 Apr 2011 Link to this post

    thanks to Alex Fidanov  but I want when hold back key or hold delete key, value display in RadMaskCurrencyInput = 0 instead of displaying nothing
  5. Umbala
    Umbala avatar
    28 posts
    Member since:
    Mar 2010

    Posted 18 Apr 2011 Link to this post

    ???
  6. Tina Stancheva
    Admin
    Tina Stancheva avatar
    3298 posts

    Posted 19 Apr 2011 Link to this post

    Hello Umbala,

    Unfortunately the MaskedInput controls don't support this scenario. I logged this issue in our PITS under the name MaskedInput: When holding the Backspace and Delete keys, the Value property doesn't match the Text property and the item will be available for tracking in approximately 24hours. I also updated your Telerik account accordingly.

    In the meantime you can try a couple of workarounds. You can handle the MaskedCurrencyInput.KeyUp() event and reset the control's Value whenever it is null or 0:
    void currencyInput_KeyUp(object sender, KeyEventArgs e)
    {
        RadMaskedCurrencyInput rmci = sender as RadMaskedCurrencyInput;
        if (e.Key == Key.Delete || e.Key == Key.Back)
        {
            if (rmci.Value == 0 || rmci.Value == null)
            {
                rmci.Value = null;
                rmci.Value = 0;
            }
        }
    }
    Or you can handle the MaskedCurrencyInput.ValueChanged() event to reset the control's Value again in case it is null or 0. But you will need to reset it in a Dispatcher:
    private void RadMaskedCurrencyInput_ValueChanged(object sender, Telerik.Windows.RadRoutedEventArgs e)
    {
        this.Dispatcher.BeginInvoke(new Action(() =>
        {
            if ((sender as RadMaskedCurrencyInput).Value == null)
            {
                (sender as RadMaskedCurrencyInput).Value = 0;
            }
        }));
     
    }


    All the best,
    Tina Stancheva
    the Telerik team
    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 Public Issue Tracking system and vote to affect the priority of the items
  7. CHRISTIAN
    CHRISTIAN avatar
    39 posts
    Member since:
    Nov 2010

    Posted 27 May 2011 Link to this post

    i´ve implemented the suggested solution in the second post on a numericinput control.
    but the control doesn´t fire the valuechanged event if the clear-button is clicked multiple times.
    so the value still can get null. also my validation doesn´t work then.
    any solution for that??
  8. CHRISTIAN
    CHRISTIAN avatar
    39 posts
    Member since:
    Nov 2010

    Posted 31 May 2011 Link to this post

    *harrumph
  9. Alex Fidanov
    Admin
    Alex Fidanov avatar
    636 posts

    Posted 31 May 2011 Link to this post

    Hi CHRISTIAN,

    The ValueChanged event will only fire when there is a change in the value. When you press it multiple times, the value does not change and stays null. What you can do, is to create your own Clear command and assign it to the control:

    maskedInput.ClearCommand = new DelegateCommand((p) =>
    {
        maskedInput.Value = null;
    });


    Greetings,
    Alex Fidanov
    the Telerik team
    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 Public Issue Tracking system and vote to affect the priority of the items
  10. federico
    federico avatar
    4 posts
    Member since:
    Mar 2015

    Posted 20 Nov 2015 Link to this post

    as is done to clear the negative? if -1.0 then 0.0  (not -0.00)

     

  11. Milena
    Admin
    Milena avatar
    204 posts

    Posted 24 Nov 2015 Link to this post

    Hi Federico,

    To achieve the described behavior you can set AllowMinusOnZeroValue property of the Mask to False: 
    <telerik:RadMaskedNumericInput
              maskedInput:MaskedInputExtensions.AllowMinusOnZeroValue="False"   />

    You can find more information in this help article.

    If the suggested approach does not work for you, could you please elaborate a bit more on your scenario by sending us a sample project or a code-snippet with the declaration of your MaskedInput. There are many combination, so for us is important to know: 
    - do you use RadMaskedNumeric or RadMaskedCurrenctInput;
    - the value the Mask property (which Mask token, it is bound or not);
    - have you implement some of the suggested approaches here (on KeyUp, ValueChanged, ClearCommand).

    Thank you in advance for you cooperation.

    Regards,
    Milena
    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
Back to Top
DevCraft banner