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

Insert behavior with decimals

7 Answers 106 Views
MaskedInput (Numeric, DateTime, Text, Currency)
This is a migrated thread and some comments may be shown as answers.
Ken
Top achievements
Rank 1
Ken asked on 12 May 2011, 03:59 PM
Hi,

I have the following masked input:

  <telerik:RadMaskedNumericInput Value="{Binding Amount, Mode=TwoWay}" 
                                                       EmptyContent="0.00" Width="350" 
                                                       Mask="#12.2" />
What I would like to happen is, if the cursor is placed at the rightmost position (i.e. the second decimal place) and the user types, then the typed values are inserted from right to left and go past the decimal point. Example:
Value is "000.00"
User types "1" -> "000.01"
User types "2" -> "000.12"
User types "3" -> "001.23"
User types "4" -> "012.34"

This behavior actually works if the cursor is to the left of the decimal point, but if it's on any of the decimal positions it doesn't.
Any idea how to enable it?

Thanks!

7 Answers, 1 is accepted

Sort by
0
Alex Fidanov
Telerik team
answered on 17 May 2011, 10:00 AM
Hi Adrian,

There is no way to change this through the public API. The numeric control will resolve its input behavior internally when the caret is behind the decimal point. What you can do however, is to inherit from the RadMaskedNumericInput control and override its InputBehaviorResolved property:

public class MyNumericInput : RadMaskedNumericInput
{
    protected override Telerik.Windows.Controls.MaskedInput.InputBehavior InputBehaviorResolved
    {
        get
        {
            return Telerik.Windows.Controls.MaskedInput.InputBehavior.Insert;
        }
    }
}
This way, the InputBehavior will always resolve as Insert - i.e. it will be always inserting from right to left.

Best wishes,
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
Ken
Top achievements
Rank 1
answered on 17 May 2011, 10:23 AM
Hi Alex,

Thanks for the answer. It almost gets me where I want, which is: when the user focuses the input, I want the caret to be at the rightmost position and all the text to be selected. This way, when the user starts typing he will start inserting numbers from right to left.

Using your suggestion this works fine if the caret is already on the rightmost position (after the decimal point). I also set SelectionOnFocus=SelectAll. However, I can't find a way to move the caret to the rightmost position. Is there a way to do this?

Example use case, let's say the input contains 63.48. User focuses the field, all should be selected and caret placed at the righmost spot so then:
1. User types 5 -> 00.05
2. User types 9 -> 00.59
3. User types 0 -> 05.90
4. User types 0 -> 59.00

Thanks!

Later edit: it seems i can do that with some SelectionStart trickery, so nevermind :)
0
Alex Fidanov
Telerik team
answered on 17 May 2011, 11:41 AM
Hi Adrian,

Have you tried setting the SelectionOnFocus to CaretToEnd:

SelectionOnFocus

 

 

="CaretToEnd"

 

This should position the caret at right most position.

All the best,
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
Ken
Top achievements
Rank 1
answered on 17 May 2011, 11:43 AM
Hi Alex,

It doesn't help because the requirement is that when the field is focused and then the user types something, the previous text is overwritten (from scratch). So I need SelectAll so everything is selected and as soon as the user types something he starts brand new.

Cheers,
Adrian
0
Alex Fidanov
Telerik team
answered on 19 May 2011, 09:38 AM
Hi Adrian,

If you need to clear the previous value, I would recommend overriding the OnGotFocus method and setting the value to null.

Best wishes,
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
Ken
Top achievements
Rank 1
answered on 19 May 2011, 10:19 AM
Hi Alex,

Actually that's not what I want. I only want the previous value to be overwritten if the user actually starts typing, not directly when the control gets focus. So far the selection mode works ok :)

Cheers,
Adrian
0
Alex Fidanov
Telerik team
answered on 20 May 2011, 08:41 AM
Hi Adrian,

Another idea that comes to mind is to use the got focus and key down events, like this:

private bool shouldClearValue = false;
protected override void OnGotFocus(RoutedEventArgs e)
{
    base.OnGotFocus(e);
    this.shouldClearValue = true;
}
protected override void OnKeyDown(KeyEventArgs e)
{
    if (shouldClearValue)
    {
        this.Value = null;
        this.shouldClearValue = false;
    }
    base.OnKeyDown(e);
}


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
Tags
MaskedInput (Numeric, DateTime, Text, Currency)
Asked by
Ken
Top achievements
Rank 1
Answers by
Alex Fidanov
Telerik team
Ken
Top achievements
Rank 1
Share this question
or