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

RadMaskedTextInput doesnot update a text when deleting

8 Answers 380 Views
MaskedInput (Numeric, DateTime, Text, Currency)
This is a migrated thread and some comments may be shown as answers.
Vladimir
Top achievements
Rank 1
Vladimir asked on 13 Feb 2018, 01:37 PM

I set FormatString="n0" on RadMaskedTextInput and it works great when adding new digits. But it doesnot update its textbox value on delete.

For example, I enter 1 000 000, it looks OK, but when I remove last digit it becomes 1 000 00 , and what we expect is 100 000

I attached a screenshot which shows how it looks like on change

Is there a workaround available to fix this? 

 

Thanks

Best regards, 

Vladimid

 

8 Answers, 1 is accepted

Sort by
0
Vladimir
Top achievements
Rank 1
answered on 15 Feb 2018, 07:19 AM

Also when I'm trying to delete from the leftmost digit with the 'delete' key, when the caret goes to the first whitespace it stops and doesnot move further, pls see the attached screenshot. This affects our test automation. Let us know if some workaround or fix is possible.

Thank you,

Vladimir

0
Petar Mladenov
Telerik team
answered on 16 Feb 2018, 09:07 AM
Hello Vladimir,

Can you send us your XAML code here ? This will help us better understand your scenario. Also, do you set Culture in XAML or in code behind ? What is your default Windows Culture setting ? Also, do you use the MaskedInput in GridView ? In a isolated sample with default (en-US) Culture there is no grouping of digits and FormatString has no effect on value in MaskedtextInput, it generally changes the formatting of doubles / decimals in MaskedNumericInput/ CurrencyInput:

<telerik:RadMaskedTextInput Value="1000000" FormatString="n0" Mask=""/>


Regards,
Petar Mladenov
Progress Telerik
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
0
Vladimir
Top achievements
Rank 1
answered on 19 Feb 2018, 07:25 AM
The xaml code is like this: we have these styles for the MaskedNumericInput control:
    <Style x:Key="GridBaseRadMaskedNumericInputStyle"
           TargetType="telerik:RadMaskedNumericInput"
           BasedOn="{StaticResource RadMaskedNumericInputStyle}">
        <Setter Property="Mask"
                Value="" />
        <Setter Property="Height"
                Value="30" />
        <Setter Property="HorizontalAlignment"
                Value="Stretch" />
        <Setter Property="SelectionOnFocus"
                Value="DefaultSelectAll" />
        <Setter Property="EmptyContent"
                Value="" />
        <Setter Property="TextMode"
                Value="PlainText" />
        <Setter Property="IsClearButtonVisible"
                Value="False" />
        <Setter Property="InputBehavior"
                Value="Insert" />
        <Setter Property="AcceptsReturn"
                Value="False" />
    </Style>

 

<Style x:Key="GridMinMaxRadMaskedNumericInputStyle"
       TargetType="telerik:RadMaskedNumericInput"
       BasedOn="{StaticResource GridBaseRadMaskedNumericInputStyle}">
    <Setter Property="maskedInput:MaskedInputExtensions.Maximum"
            Value="10000000000000" />
    <Setter Property="maskedInput:MaskedInputExtensions.Minimum"
            Value="0" />
    <Setter Property="FormatString" Value="n0"/>
    <Setter Property="UpdateValueEvent" Value="LostFocus" />
</Style>
0
Vladimir
Top achievements
Rank 1
answered on 19 Feb 2018, 07:27 AM
And the contol itself is : 
<telerik:GridViewDataColumn Header="Header"
                                                DataMemberBinding="{Binding SomeProp}"
                                                DataFormatString="n0"
                                                TextAlignment="Right"
                                                CellStyle="{StaticResource GridViewCellWarningyStyle}">
                        <telerik:GridViewDataColumn.CellEditTemplate>
                            <DataTemplate>
                                <telerik:RadMaskedNumericInput Value="{Binding SomeProp,TargetNullValue=''}"
                                                               Style="{StaticResource GridMinMaxRadMaskedNumericInputStyle }"
                                                               maskedInput:MaskedInputExtensions.Maximum="1000000000" />
                            </DataTemplate>
                        </telerik:GridViewDataColumn.CellEditTemplate>
                    </telerik:GridViewDataColumn>
0
Vladimir
Top achievements
Rank 1
answered on 19 Feb 2018, 07:31 AM

The culture is used a default Windows culture and is not changed in the code. I don't think it affects this somehow, because when I edit the text it formats Okay, the issues appear only when I delete some digits from the right or delete with Insert button

0
Petar Mladenov
Telerik team
answered on 21 Feb 2018, 08:02 AM
Hi Vladimir,

I am sending you a test project where I used most of your code to replicate the mentioned behavior. I didn't succeed in reproducing the issue. Please note the test is doe with our latest binaries from R1 2018. Could you please your scenario with latest binaries as well ?

Regards,
Petar Mladenov
Progress Telerik
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
0
Vladimir
Top achievements
Rank 1
answered on 23 Feb 2018, 07:31 AM

Petar, 

Thank you for your help. 

I tried again with the latest and looked at your test project and here is my latest finding: actually it works when I set UpdateValueEvent="PropertyChanged". And it doesnot work when I set UpdateValueEvent="LostFocus". I tried this in my project, as unfortunately I could not see affect of this setting in your test project as I got white blank window when running your project.

 

 

0
Accepted
Martin Ivanov
Telerik team
answered on 27 Feb 2018, 04:31 PM
Hello Vladimir,

I went through this forum and as I understand your issue is that the value of the Text property of control is not updated when you delete digits from the Value. If so, note that this behavior is expected. The Text property will be updated only when the UpdateValueEvent kicks-in. By default this is LostFocus. So, if you change it to PropertyChanged the Text will be updated immediately when you delete a digit. Otherwise, you will need to focus another control to update the Text.

About the Peter's project, I guess you don't see anything because Visual Studio has automatically referenced the NoXaml dll in the project. To resolve this by referencing the Xaml dlls. Check the Xaml vs. NoXaml article for more information on this.

As for the empty space deleting behavior, this is also part of the control's default behavior. I believe that the purpose of the question for the culture asked by Peter was to indicate if the empty spaces are the thousands separator (NumberGroupSeparator). Note that the mask uses the culture settings for some of its settings. Usually, if you hit delete and the caret is at the thousands separator index, the control won't do anything. To achieve your requirement here you can create a custom control that derives from RadMaskedNumericInput and subscribe to its KeyDown event. Then if the caret is on the thousands separator you can move the cursor with a position forward. Here is an example in code:
public class CustomInput : RadMaskedNumericInput
{
    public CustomInput() : base()
    {          
        this.AddHandler(RadMaskedNumericInput.KeyDownEvent, new KeyEventHandler(RadMaskedNumericInput_KeyDown), true);
    }
     
    private void RadMaskedNumericInput_KeyDown(object sender, KeyEventArgs e)
    {
        // if the Delete key is pressed &&
        // if is valid selection &&
        // if the symbol on the selection start is the ',', ' ' or whatever NumberGroupSeparator is applied
        if (Keyboard.IsKeyDown(Key.Delete) &&
            this.SelectionStart < this.Text.Length &&
            this.Text[this.SelectionStart].ToString().Equals(this.Culture.NumberFormat.NumberGroupSeparator))
        {
            this.SelectionStart++;
        }
    }
}
It is not necessary to create a custom control, you can just subscribe to the event also in code behind. However, with the custom control you get the reusability. 

I hope that helps.

Regards,
Martin Ivanov
Progress Telerik
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
Tags
MaskedInput (Numeric, DateTime, Text, Currency)
Asked by
Vladimir
Top achievements
Rank 1
Answers by
Vladimir
Top achievements
Rank 1
Petar Mladenov
Telerik team
Martin Ivanov
Telerik team
Share this question
or