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

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

5 Answers 33 Views
MaskedEditBox
This is a migrated thread and some comments may be shown as answers.
Danilo
Top achievements
Rank 1
Danilo asked on 30 Mar 2016, 08:31 AM

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

5 Answers, 1 is accepted

Sort by
0
Dimitar
Telerik team
answered on 30 Mar 2016, 01:50 PM
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.
0
Danilo
Top achievements
Rank 1
answered on 30 Mar 2016, 02:12 PM

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

0
Accepted
Dimitar
Telerik team
answered on 31 Mar 2016, 02:03 PM
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.
0
Danilo
Top achievements
Rank 1
answered on 31 Mar 2016, 02:46 PM

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

0
Dimitar
Telerik team
answered on 04 Apr 2016, 01:19 PM
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.
Tags
MaskedEditBox
Asked by
Danilo
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
Danilo
Top achievements
Rank 1
Share this question
or