MaskedTextBox Rule does not working

5 posts, 1 answers
  1. Dongfen
    Dongfen avatar
    19 posts
    Member since:
    Dec 2012

    Posted 25 Apr 2014 Link to this post

    I upgrade my kendo UI for MVC to 2014.1.415

    I want to add rule to the masked text box.  So I copied the example from this page:
    http://docs.telerik.com/kendo-ui/getting-started/using-kendo-with/aspnet-mvc/helpers/maskedtextbox/overview

    Here is my view:
    --------------------
    @{
        ViewBag.Title = "MaskedTextWithRule";
    }

    <h2>MaskedTextWithRule</h2>


    <div class="demo-section">
        <h2>Mask Input </h2>
        <ul id="fieldlist">
            <li>
                <label for="phone_number">Phone number:</label>
                @(Html.Kendo().MaskedTextBox()
                      .Name("phone_number")
                      .Mask("(999) 000-0000")
                      .Value("555 123 4567")
                )
            </li>

            <li>
                @(Html.Kendo().MaskedTextBox()
                      .Name("maskedtextbox")
                      .Rules(rules => {
                          rules.Add("~", "/[+-]/");
                      })
                      .Mask("~0000") //Set a mask with custom rule
                )
            </li>

        </ul>
    </div>

    <style>
        .demo-section {
            width: 300px;
            margin: 35px auto 50px;
            padding: 30px;
        }

        .demo-section h2 {
            text-transform: uppercase;
            font-size: 1.2em;
            margin-bottom: 10px;
        }

        #fieldlist
        {
            margin:0;
            padding:0;
        }

        #fieldlist li
        {
            list-style:none;
            padding:10px 0;
        }

        #fieldlist label {
            display: inline-block;
            width: 130px;
            margin-right: 5px;
            text-align: right;
        }
    </style>

    ---------------------------------------------------

    I compiled the project without problem, but when I run it, I got the following error
    --------------------------------------------
    Server Error in '/' Application.Compilation Error Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

    Compiler Error Message: CS1502: The best overloaded method match for 'Kendo.Mvc.UI.Fluent.MaskedTextBoxRulesBuilder.Add(char, string)' has some invalid arguments

    Source Error:

    Line 22: .Name("maskedtextbox")
    Line 23: .Rules(rules => {
    Line 24: rules.Add("~", "/[+-]/");
    Line 25: })
    Line 26: .Mask("~0000") //Set a mask with custom rule


  2. Georgi Krustev
    Admin
    Georgi Krustev avatar
    3707 posts

    Posted 28 Apr 2014 Link to this post

    Hello Dongfen,

    As it is mentioned in the exception message, the Add method accepts only System.Char type for the first parameter. The functionality is incorrectly documented. We will address the issue immediately. Check the updated documentation.
    I updated your Telerik points because of the involvement.

    Regards,
    Georgi Krustev
    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.

     
  3. UI for ASP.NET MVC is VS 2017 Ready
  4. Dongfen
    Dongfen avatar
    19 posts
    Member since:
    Dec 2012

    Posted 28 Apr 2014 in reply to Georgi Krustev Link to this post

    Thank you, Georgi,

    I added the text tag, and I can get to the page.
    But when I tried to enter + or -, it won't take it.  It only allow 5 digit.


                @(Html.Kendo().MaskedTextBox()
                      .Name("maskedtextbox")
                      .Rules(rules => {
                          rules.Add('~', @<text>"/[+-]/"</text>);
                      })
                      .Mask("~0000") //Set a mask with custom rule
                )



  5. Answer
    Georgi Krustev
    Admin
    Georgi Krustev avatar
    3707 posts

    Posted 29 Apr 2014 Link to this post

    Hello again Dongfen,


    The Add(System.Char,System.Func<System.Object,System.Object>) method should be used when the developer wants to specify a function for the specific rule. When a RegExp is set then you will need to use the first overload. You can refer to the examples into the documentation. For your convenience I prepared a simple test project, which is attached to this page.


    Regards,
    Georgi Krustev
    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. Dongfen
    Dongfen avatar
    19 posts
    Member since:
    Dec 2012

    Posted 29 Apr 2014 in reply to Georgi Krustev Link to this post

    Thanks.
    I thought I did the same thing, but it did not work at first.
    I found the difference is the single quote for the first Char in Add argument.
    Thanks 
Back to Top
UI for ASP.NET MVC is VS 2017 Ready