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

No UpperCase Input when UpdateValueEvent is LostFocus

5 Answers 110 Views
MaskedInput (Numeric, DateTime, Text, Currency)
This is a migrated thread and some comments may be shown as answers.
Peter
Top achievements
Rank 2
Iron
Iron
Veteran
Peter asked on 23 Feb 2021, 02:39 PM

Hello,

I have a problem with the RadMaskedTextInput-Control.

When I set the UpdateValueEvent-Property to LostFocus, then the input isn't converted to UpperCase anymore.

 

My xaml looks like this:

<telerik:RadMaskedTextInput Width="140" Height="22"
                            IsClearButtonVisible="False"
                            InputBehavior="Replace"
                            Mask=">X8"
                            SelectionOnFocus="Unchanged"
                            TextMode="MaskedText"
                            UpdateValueEvent="LostFocus"
                            Value="affeaffe"/>

 

I defined a ValidationRule to allow only Hex-Value for Input:

public class HexToken : ITokenValidationRule
    {
        public bool IsRequired
        {
            get { return false; }
        }
        public bool IsValid(char ch)
        {
            return ValidChars.Contains(ch);
        }
        public char Token
        {
            get { return 'X'; }
        }
        public TokenTypes Type
        {
            get { return TokenTypes.AlphaNumeric; }
        }
        private string myValidChars = "0123456789abcdefABCDEF";
        public string ValidChars
        {
            get { return myValidChars; }
        }
    }

 

Can you help me with this plz?

regards,

Tobias

5 Answers, 1 is accepted

Sort by
0
Dilyan Traykov
Telerik team
answered on 26 Feb 2021, 12:38 PM

Hello Tobias,

Thank you for the provided code snippets.

The behavior you described is expected as when you set the UpdateValueEvent property to LostFocus the inputted value is only parsed once the control loses focus which means that any new characters won't be processed (by the > modifier token) until then. If you want to have each character  be transformed to uppercase, you would need to manually handle the input per keystroke.

I hope this clarifies things for you.

Regards,
Dilyan Traykov
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

0
Peter
Top achievements
Rank 2
Iron
Iron
Veteran
answered on 01 Mar 2021, 09:37 AM

Hello Dilyan,

thanks for your response. That's a little bit disappointing, because the default-Input behaviour on GridView is (imho) LostFocus.

I followed your suggestion but it's not as easy as it seems. Can you provide me an example how to manually handle the input per keystroke?

Thanks, Tobias

0
Dilyan Traykov
Telerik team
answered on 04 Mar 2021, 09:20 AM

Hello Peter,

As per your request, I've prepared a small sample project to demonstrate how you can manually handle the text input and make it uppercase.

It involves handling the TextInput event of the PreviewInputTextBox inside the RadMaskedTextInput in the following manner:

        private void OnTextChanged(object sender, RoutedEventArgs e)
        {
            var input = sender as PreviewInputTextBox;
            var currentText = input.Text;
            var upperText = currentText.ToUpper();
            if (upperText != currentText)
            {
                input.Text = upperText;
            }
        }

Please have a look and let me know if such an approach would work for you.

Regards,
Dilyan Traykov
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

0
Peter
Top achievements
Rank 2
Iron
Iron
Veteran
answered on 08 Mar 2021, 07:20 AM

Hello Dilyan,

thank you very much for the provided code snippet.

It works, but I changed it a little bit to reset the Caret-Position after setting the UpperText:

private void OnTextChanged(object sender, RoutedEventArgs e)
{
    var textBox = sender as PreviewInputTextBox;
 
    var caretIndex = textBox.CaretIndex;
    var upperText = textBox.Text.ToUpper();
    if (upperText != textBox.Text)
    {
        textBox.Text = upperText;
        textBox.CaretIndex = caretIndex;
    }
}

 

Cheers!

Tobias

0
Dilyan Traykov
Telerik team
answered on 09 Mar 2021, 02:06 PM

Hello Tobias,

I'm happy to hear that you've managed to achieve the desired result. I'd also like to thank you for sharing your solution with our community.

Regards,
Dilyan Traykov
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
MaskedInput (Numeric, DateTime, Text, Currency)
Asked by
Peter
Top achievements
Rank 2
Iron
Iron
Veteran
Answers by
Dilyan Traykov
Telerik team
Peter
Top achievements
Rank 2
Iron
Iron
Veteran
Share this question
or