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

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

9 Answers 332 Views
MaskedInput (Numeric, DateTime, Text, Currency)
This is a migrated thread and some comments may be shown as answers.
Umbala
Top achievements
Rank 1
Umbala asked on 11 Apr 2011, 03:53 AM
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!

9 Answers, 1 is accepted

Sort by
0
Alex Fidanov
Telerik team
answered on 11 Apr 2011, 08:13 AM
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
0
Umbala
Top achievements
Rank 1
answered on 15 Apr 2011, 02:44 AM
thanks to Alex Fidanov  but I want when hold back key or hold delete key, value display in RadMaskCurrencyInput = 0 instead of displaying nothing
0
Umbala
Top achievements
Rank 1
answered on 18 Apr 2011, 05:39 AM
???
0
Tina Stancheva
Telerik team
answered on 19 Apr 2011, 05:47 PM
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
0
CHRISTIAN
Top achievements
Rank 1
answered on 27 May 2011, 01:23 PM
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??
0
CHRISTIAN
Top achievements
Rank 1
answered on 31 May 2011, 08:54 AM
*harrumph
0
Alex Fidanov
Telerik team
answered on 31 May 2011, 09:04 AM
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
0
federico
Top achievements
Rank 1
answered on 20 Nov 2015, 07:35 PM

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

 

0
Milena
Telerik team
answered on 24 Nov 2015, 08:47 AM
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
Tags
MaskedInput (Numeric, DateTime, Text, Currency)
Asked by
Umbala
Top achievements
Rank 1
Answers by
Alex Fidanov
Telerik team
Umbala
Top achievements
Rank 1
Tina Stancheva
Telerik team
CHRISTIAN
Top achievements
Rank 1
federico
Top achievements
Rank 1
Milena
Telerik team
Share this question
or