MaskedBox switch between MaskType Regex and None is still validating the value

6 posts, 1 answers
  1. Danilo
    Danilo avatar
    40 posts
    Member since:
    Sep 2012

    Posted 30 Mar Link to this post

    Hi Telerik Team

    I'm facing another problem using RadMaskedEditBox. I'm trying to disable the validation using a checkbox. If the checkbox is checked, the EditBox uses MaskType.Regex and a regex mask. If the checkbox is unchecked, it should not validate the control anymore. I'm clearing Mask property and set MaskType to None. But the control is always validating. To reproduce this behaviour you can do the following:

    1. Add a RadMaskedEditBox and a RadCheckbox to your form.
    2. Add ToggleStateChanged event to the RadCheckbox.
    3. Use the following code:

    private void radCheckBox1_ToggleStateChanged(object sender, StateChangedEventArgs args)
    {
        if (args.ToggleState == Telerik.WinControls.Enumerations.ToggleState.On)
        {
            radMaskedEditBox1.Mask = "^[0-9]{5}$";
            radMaskedEditBox1.MaskType = MaskType.Regex;
        }
     
        else if (args.ToggleState == Telerik.WinControls.Enumerations.ToggleState.Off)
        {
            radMaskedEditBox1.Mask = "";
            radMaskedEditBox1.MaskType = MaskType.None;
        }
    }

    4. Start the application
    5. Check and uncheck the checkbox (now ToggleStateChanged event was fired)
    6. Type some letters to the RadMaskedEditBox (e.g. "aaa")
    7. Press tab

    The error icon right next to the RadMaskedEditBox appears. But the MaskType is set to none and the Mask property is also empty. The documentation about this control says the following:

    • None: the control acts like a text box.

    Am I doing something wrong? Do I have to remember something? Or is this a bug?

    Regards,
    Danilo

  2. Dimitar
    Admin
    Dimitar avatar
    1404 posts

    Posted 30 Mar Link to this post

    Hello Danilo,

    Thank you for writing back.

    Your code is correct and this is an issue with our control. I have logged the issue in our Feedback Portal. The issue is caused because the old provider is still checking for valid input even when the MaskType is changed. You can track the item for status changes and add your vote for it here.

    To workaround this, you can change the mask in the hosted textbox Leave event handler. Here is a complete example:
    RegexMaskTextBoxProvider provider;
    private void radCheckBox1_ToggleStateChanged(object sender, Telerik.WinControls.UI.StateChangedEventArgs args)
    {
        if (args.ToggleState == Telerik.WinControls.Enumerations.ToggleState.On)
        {
            radMaskedEditBox1 = new RadMaskedEditBox();
            radMaskedEditBox1.Mask = "^[0-9]{5}$";
            radMaskedEditBox1.MaskType = MaskType.Regex;
            radMaskedEditBox1.MaskedEditBoxElement.TextBoxItem.HostedControl.Leave += HostedControl_Leave;
            provider = (RegexMaskTextBoxProvider) radMaskedEditBox1.MaskedEditBoxElement.Provider;
        }
     
        else if (args.ToggleState == Telerik.WinControls.Enumerations.ToggleState.Off)
        {
            radMaskedEditBox1.MaskedEditBoxElement.Mask = "";
            radMaskedEditBox1.MaskType = MaskType.None;
        }
    }
     
    private void HostedControl_Leave(object sender, EventArgs e)
    {
        if (radMaskedEditBox1.MaskType == MaskType.None && provider != null)
        {
            provider.GetType().GetField("mask", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance).SetValue(provider, "*");
        }
    }

    Your Telerik Points have been updated for this report.

    Should you have any other questions do not hesitate to ask.


    Regards,
    Dimitar
    Telerik
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Danilo
    Danilo avatar
    40 posts
    Member since:
    Sep 2012

    Posted 30 Mar in reply to Dimitar Link to this post

    Hello Dimitar

    Thanks for your answer. Do you know how long it will take you to fix this problem?

    I tried your code but with this code it doesn't validate anything, even when the checkbox is checked. It has to validate when checkbox is checked, and not validate when checkbox is unchecked.

    Do you have any further suggestions?

    Regards,
    Danilo

  5. Answer
    Dimitar
    Admin
    Dimitar avatar
    1404 posts

    Posted 31 Mar Link to this post

    Hi Danilo,

    Thank you for writing back.

    Yes, I can confirm that the workaround fails at some point. We are already working on this issue and the fix will be available in the next official release (it is scheduled for the beginning of May).

    Unfortunately, the only other workaround I can suggest is to create a new control every time the you need to change the MaskType.

    I hope this information is useful.

    Regards,
    Dimitar
    Telerik
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
  6. Danilo
    Danilo avatar
    40 posts
    Member since:
    Sep 2012

    Posted 31 Mar in reply to Dimitar Link to this post

    Hello Dimitar

    Okay, then I'll create another workaround with a different control as you suggested. I'm looking forward to this release. Thank you for the support.

    Regards,
    Danilo

  7. Dimitar
    Admin
    Dimitar avatar
    1404 posts

    Posted 04 Apr Link to this post

    Hello Danilo,

    I am glad I could be of help. Let us know if you have any other questions.
     
    Regards,
    Dimitar
    Telerik
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
Back to Top
UI for WinForms is Visual Studio 2017 Ready