Cancel OnClientSearch

2 posts, 0 answers
  1. Mike
    Mike avatar
    59 posts
    Member since:
    Jan 2008

    Posted 04 Mar 2014 Link to this post

    Hello,

    I've sound some other discussions in the forum on not posting back with a client search, but, I'd like it to leave the drop down open. This happens if the client search function throws an error, so I feel like there should be a way to tell it to cancel and not close the results box. Here's what I have right now:

    function txtAutoSearch_Search(sender, args) {
        if (args.get_value() == null) {
            sender._element.control._postBackOnSearch = false;
        } else {
            sender._element.control._postBackOnSearch = true;
        }
    }

    This actually works very nicely as a way to make it so that, if they haven't selected a result, it won't post back. But, when people hit "enter", the results still close, and that confuses some folks. Is there a way to safely cancel the post and leave the box open? Basically, some line I could add after the "_postBackOnSearch = false;" bit?

    Thanks,

    Mike

  2. Nencho
    Admin
    Nencho avatar
    1458 posts

    Posted 07 Mar 2014 Link to this post

    Hello Mike,

    Please consider adding the following overwrite to your page. In addition you could use the case key.enter, in order to apply additional modifications if needed:

    <script type="text/javascript">
     
           Telerik.Web.UI.RadSearchBox.prototype._onKeyDown = function (e) {
               var $T = Telerik.Web.UI;
               var keyCode = e.keyCode,
                   key = Sys.UI.Key,
                   keyboardNavigator = this._keyboardNavigator;
     
               switch (keyCode) {
                   case key.up:
                       {
                           e.preventDefault();
                           if (this.get_enableAutoComplete()) {
                               keyboardNavigator._updateHighlightedItem($T.HighlightItemDirection.Up);
                           }
                       }
                       break;
                   case key.down:
                       {
                           e.preventDefault();
                           if (this.get_enableAutoComplete()) {
                               keyboardNavigator._updateHighlightedItem($T.HighlightItemDirection.Down);
                           }
                       }
                       break;
                   case key.enter:
                       {
                           var itemData = null;
     
                           e.preventDefault();
                           if (this._highlightedItem) {
                               itemData = this._highlightedItem._data;
                               this._updateInputValue(itemData);
                           }
     
                           // this._raiseSearch(itemData);
                           //this.clear();
                       }
                       break;
                   case key.esc:
                       {
                           e.preventDefault();
                           this.get_inputElement().value = "";
                           this.clear();
                       }
                       break;
               }
           }
       </script>


    Regards,
    Nencho
    Telerik

    DevCraft Q1'14 is here! Watch the online conference to see how this release solves your top-5 .NET challenges. Watch on demand now.

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