RadMaskedTextBox - Require complete text or empty

6 posts, 0 answers
  1. Richard
    Richard avatar
    14 posts
    Member since:
    Oct 2010

    Posted 16 Jul 2014 Link to this post

    I see there is a property of the RadMaskedTextBox called RequireCompleteText which will verify the full mask is satisfied. Is there a way to only enable this if a value has been entered? Basically, I want the user to be able to submit the form with either nothing in the field, or the complete text if they decide to enter a value. Right now, an empty field fails the RequireCompleteText validation.
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 16 Jul 2014 in reply to Richard Link to this post

    Hi Richard,

    Try to attach the OnKeyPress client event and set requireCompleteText property as true.

    JavaScript:
    function validateValue(sender, args) {
        sender._requireCompleteText = true;
    }

    Please provide your code if it doesn't help.
    Thanks,
    Shinu.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Joel Kraft
    Joel Kraft avatar
    87 posts
    Member since:
    Jan 2004

    Posted 30 Dec 2014 in reply to Shinu Link to this post

    Hello,

    I have this same question and I'm not quite sure how your answer applies.
    Here would be an example markup for the masked textbox:

    <TELERIK:RadMaskedTextBox runat="server" ID="test" Mask="###/###-####" EmptyMessage="(none)" SelectionOnFocus="SelectAll" RequireCompleteText="true" />

    The input should be acceptable if the box is completely empty, or the entire mask is filled:
    • (empty)
    • 123/456-7890
    • 555/555-1212
    Unacceptable Input
    • 123/___-____
    • 123/456-000_
    • ___/456-4560
    The current behavior of RequireCompleteText doesn't appear to allow for empty input. I would normally expect to enforce this either via a RequiredFieldValidator, or the IsRequired in RadInputManger...

    Joel
  5. Kostadin
    Admin
    Kostadin avatar
    1708 posts

    Posted 05 Jan 2015 Link to this post

    Hi Joel,

    Generally when RequireCompleteText is enabled and no text is entered in the input element by default it should prevent submitting the form. Nevertheless you can workaround this behavior by manually change the valid state of the control. For this purpose you can hook OnBlur client event and if the input element is empty to set invalid property to false. Please check out the following code snippet.
    <script type="text/javascript">
        function OnBlur(sender, args) {
            if (sender.get_value().length == 0) {
                sender.set_invalid(false);
            }
        }
    </script>
     
    <telerik:RadMaskedTextBox runat="server" ID="test" Mask="###/###-####" RequireCompleteText="true" SelectionOnFocus="SelectAll" ClientEvents-OnBlur="OnBlur" />


    Regards,
    Kostadin
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  6. Joel Kraft
    Joel Kraft avatar
    87 posts
    Member since:
    Jan 2004

    Posted 05 Jan 2015 in reply to Kostadin Link to this post

    Personally, I think the required part would be left to the RequiredFieldValidator to be consistent with how other things in the framework, such as the RegularExpressionValidator, work. I can't really think of another instance where empty would be an error in this way.

    But the workaround does work fine.
  7. Kostadin
    Admin
    Kostadin avatar
    1708 posts

    Posted 08 Jan 2015 Link to this post

    Hi Joel,

    Note that by default RequireCompleteText is implemented to work with RequiredFieldValidator. So generally you have to enabled both of them if you need to work correctly. Otherwise you have to disable RequireCompleteText and use some other validation control.

    Regards,
    Kostadin
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017