text keeps its value even if set_Cancel() is set to true

6 posts, 0 answers
  1. Elisabeth
    Elisabeth avatar
    8 posts
    Member since:
    Nov 2012

    Posted 26 Nov 2012 Link to this post

    I am trying to use the AutoCompleteBox control.

    I only want to let the user select one instance of each token. My list of tokens contains "Test 1, "Test 2" and "Test 3".

    I am using a function on the OnClientEntryAdding that checks whether the entry has already been added.
    <script type="text/javascript">
        function entryAdding(sender, eventArgs) {
            var txt = sender.get_text();
            var entries = sender.get_entries(),
            count = entries.get_count();
            for (var i = 0; i < count; i++) {
                if (entries.getEntry(i).get_value() == eventArgs.get_entry().get_value()) {
                    eventArgs.set_cancel(true);
                }
            }
        }
    </script>

    If I type in "Test" and select "Test 1", it's added to the list of tokens. If I type in "tes" and then select "Test 1" then the token is not added which is what I want. But if I then type in "tes" and select "Test 1" then the event is cancelled but the text in the control is "Test 1 ;tes". It seems that the text is still changed even if the entry has been cancelled. How can I prevent it from adding an invalid token?

    If I save the entries, then it's ok because the collection of entries doesn't contain the invalid entry but I don't want to display that invalid entry.

    Below is the setting of my control

    <telerik:RadAutoCompleteBox runat="server" ID="ACBVoie" DataTextField="Desc_No_Voie" DataValueField="No_Voie" InputType="Token" width="100%" OnClientEntryAdding="entryAdding" AllowCustomToken="false">
    </telerik:RadAutoCompleteBox >

    Thanks




  2. Elisabeth
    Elisabeth avatar
    8 posts
    Member since:
    Nov 2012

    Posted 29 Nov 2012 Link to this post

    Hi,

    am I the only one with this problem?

    Thanks
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Nencho
    Admin
    Nencho avatar
    1458 posts

    Posted 29 Nov 2012 Link to this post

    Hi Elisabeth,

    I have performed some test, based on provided snippet of code and information, but I was unable to replicate the described issue. I have prepared a sample project for you, demonstrating the behavior at my end. In addition, I have recorded a video on the matter.

    Regards,
    Nencho
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  5. Srimanta
    Srimanta avatar
    5 posts
    Member since:
    Mar 2013

    Posted 18 Mar 2013 Link to this post

    Hi,

    I am also facing same, when I am trying to restrict duplicate entry to autocomplete text box. This is happening for ItemType = 'Token' .
    When I am selecting token already selected from autocomplete text dropdown, normal text is adding along with existing Token for the same Token.

    Please suggest any solution for the same.

    My Codes:

                        <telerik:RadAutoCompleteBox ID="TextAutoComplete" Width="180" DropDownHeight="150" DropDownWidth="200" OnClientRequesting="OnAutoCompleteRequesting" 
                                    OnClientEntryAdding="EntryAdding" runat="server">
                            <WebServiceSettings Method="GetRadCompletions" Path="../../Shared/WebServices/AutoCompleteExcelLikeFilter.asmx" />
                        </telerik:RadAutoCompleteBox>



    And script is:

    function EntryAdding(sender, eventArgs) {
        var entries = sender.get_entries();
        var count = entries.get_count();
        for (var i = 0; i < count; i++) {
            if (entries.getEntry(i).get_value() == eventArgs.get_entry().get_value()) {
                eventArgs.set_cancel(true);
            }
        }
    }
  6. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 19 Mar 2013 Link to this post

    Hi,

    Please try the following code snippet for avoiding duplicate entry of tokens. I have applied a small trick to avoid the duplication but the already added item appears at the last position in the AutoCompleteBox.

    JavaScript:
    <script type="text/javascript">
        function EntryAdding(sender, eventArgs) {
            var entries = sender.get_entries();
            var count = entries.get_count();
            for (var i = 0; i < count; i++) {
                if (entries.getEntry(i)._text == eventArgs.get_entry()._text) {
                    alert("Item Already Added");
                    var entry1 = sender.get_entries().getEntry(i);
                    sender.get_entries().remove(entry1);
                    break;
                }
            }
        }
    </script>

    Thanks,
    Princy.
  7. Srimanta
    Srimanta avatar
    5 posts
    Member since:
    Mar 2013

    Posted 19 Mar 2013 Link to this post

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