This is a migrated thread and some comments may be shown as answers.

Cancel OnClientSearch

2 Answers 75 Views
SearchBox
This is a migrated thread and some comments may be shown as answers.
Mike
Top achievements
Rank 1
Mike asked on 04 Mar 2014, 05:08 PM
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 Answers, 1 is accepted

Sort by
0
Nencho
Telerik team
answered on 07 Mar 2014, 01:05 PM
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.

0
Kasim
Top achievements
Rank 2
answered on 12 Mar 2019, 05:08 AM

Hi Nencho,

I tried a slightly different way to fix the issue. Posting it here so it can be useful for other users facing issue.

1.function Search_OnClientSearch(sender, args) {
2.    if (sender._highlightedItem === null) {
3.        sender._element.control._postBackOnSearch = false;
4.    }
5.}
Tags
SearchBox
Asked by
Mike
Top achievements
Rank 1
Answers by
Nencho
Telerik team
Kasim
Top achievements
Rank 2
Share this question
or