Insert behavior with decimals

8 posts, 0 answers
  1. Ken
    Ken avatar
    104 posts
    Member since:
    Aug 2010

    Posted 12 May 2011 Link to this post

    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!
  2. Alex Fidanov
    Admin
    Alex Fidanov avatar
    636 posts

    Posted 17 May 2011 Link to this post

    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
  3. DevCraft banner
  4. Ken
    Ken avatar
    104 posts
    Member since:
    Aug 2010

    Posted 17 May 2011 Link to this post

    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 :)
  5. Alex Fidanov
    Admin
    Alex Fidanov avatar
    636 posts

    Posted 17 May 2011 Link to this post

    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
  6. Ken
    Ken avatar
    104 posts
    Member since:
    Aug 2010

    Posted 17 May 2011 Link to this post

    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
  7. Alex Fidanov
    Admin
    Alex Fidanov avatar
    636 posts

    Posted 19 May 2011 Link to this post

    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
  8. Ken
    Ken avatar
    104 posts
    Member since:
    Aug 2010

    Posted 19 May 2011 Link to this post

    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
  9. Alex Fidanov
    Admin
    Alex Fidanov avatar
    636 posts

    Posted 20 May 2011 Link to this post

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