Editable RadAutoComleteBox input area max length

4 posts, 0 answers
  1. Sudhanshu
    Sudhanshu avatar
    2 posts
    Member since:
    Jan 2014

    Posted 03 Jan 2014 Link to this post

       How to set max length of input area for editable RadAutoComleteBox  so that use can not enter more than specified max length?
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 03 Jan 2014 Link to this post

    Hi Sudhanshu,

    I guess you want to limit the entries into the RadAutoCompleteBox, you can try handling the OnClientEntryAdding event in this way:

    ASPX:
    <telerik:RadAutoCompleteBox ID="RadAutoCompleteBox2" runat="server" OnClientEntryAdding="OnClientEntryAddingHandler". . . .>
    </telerik:RadAutoCompleteBox>

    JS:
    <script type="text/javascript">
        function OnClientEntryAddingHandler(sender, eventArgs) {
            if (sender.get_entries().get_count() > 0) {
                eventArgs.set_cancel(true);
                alert("You can select only one entry");
            }
        }    
    </script>

    Thanks,
    Princy
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Sudhanshu
    Sudhanshu avatar
    2 posts
    Member since:
    Jan 2014

    Posted 04 Jan 2014 Link to this post

    Hi Princy,
                 thanks for reply, But I want user can not enter character after specific length(Eg. 20) in RadAutoCompleteBox.
  5. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 04 Jan 2014 Link to this post

    Hi Sudhanshu,

    Please try the following JavaScript to set the maximumLength for RadAutoCompleteBox.

    JavaScript:
    <script type="text/javascript">
        var maxLength = 20;
        $(".racInput").keyup(function () {
            var text = $(this).val();
            var textLength = text.length;
            if (textLength > maxLength) {
                $(this).val(text.substring(0, (maxLength)));
                alert("Sorry, you only " + maxLength + " characters are allowed");
            }
        });
    </script>

    Hope this will helps you.
    Thanks,
    Princy.

Back to Top