angular-advanced-searchbox icon indicating copy to clipboard operation
angular-advanced-searchbox copied to clipboard

Submit Search.

Open vikasgupta1986 opened this issue 10 years ago • 13 comments

I tried this directive but ran into an issue with submitting my search. Seems like, as you start typing in the search box, the "ng-model" variable changes. What i want to do is: submit search when user has entered a value. I tried it by putting a watch on the "ng-model" variable, but that didn't work. Any ideas?

vikasgupta1986 avatar Jan 14 '15 23:01 vikasgupta1986

Same for "delete". In my controller, how do i know that the search has been cleared.

vikasgupta1986 avatar Jan 14 '15 23:01 vikasgupta1986

Can you please post your example?

The ng-model variable is updated every time when something changes, with a build in throttling of 500 ms: https://github.com/dnauck/angular-advanced-searchbox/blob/master/src/angular-advanced-searchbox.js#L175

I simply attach this nd-model variable to the paginate-anything directive to query my service. its also possible to watch it and use it directly as params for the $http service.

dnauck avatar Jan 15 '15 16:01 dnauck

Thanks for the response. Here is my example:

  1. Lets say i have 1 parameter called as "User".
  2. Now i click on the search box, then i click on "User" to apply it.
  3. Now I enter a username say, "Jim" and press Enter.

So, in this flow, as you mentioned in your comment, the ng-model variable keeps updating as I select a parameter or as i am writing the user name. What I want to do is, make an API call after the user has finished entering his "user" name and hit Enter. How can I do that?

vikasgupta1986 avatar Jan 15 '15 18:01 vikasgupta1986

As I think more, one way to do that could be to have a "Submit" button. But the drawback to that is that even when the user clears a search term from the text box, the "Submit" needs to be pressed. There is no way to detect if the textbox was cleared or a search term was removed by clicking on the "trash" icon.

vikasgupta1986 avatar Jan 15 '15 18:01 vikasgupta1986

To receive internal status changes we need to implement some events you can watch on. Maybe this is what you need.

dnauck avatar Jan 20 '15 06:01 dnauck

Yes, thats correct.

vikasgupta1986 avatar Feb 11 '15 03:02 vikasgupta1986

I'll investigate if we go for events or callbacks.

dnauck avatar Feb 12 '15 05:02 dnauck

Do you want to know when a user leaves a search parameter (onBlur)? What about the search box?

Maybe you should watch the ng-model and just call your api when the whole directive loses its focus?

dnauck avatar May 13 '15 16:05 dnauck

Hi, you can put your search box inside a form with ng-submit directive. You can then write a function for retrieving data, that will be triggered when user hits enter.

There is just one little problem, in order for this to work you need to change template of search directive Change "ng-show" into "ng-if" in lines 13, 20 :). or the form will not be submitted

veki12 avatar May 15 '15 13:05 veki12

Upss,

I just saw that the ng-show is already replaced with ng-if in the new version of directive

veki12 avatar May 15 '15 13:05 veki12

+1 for having a callback/event when the searchbar changes focus

darcys22 avatar Jul 17 '15 01:07 darcys22

The event advanced-searchbox:leavedEditMode does not solve the problem of submit. It should open suggestions box only when mouse click happens, not during enter button press or leave event. I think, it will be nicer if it calls the submit event when enter button is pressed (or) remove or remove all is invoked.

fizerkhan avatar Jan 21 '16 09:01 fizerkhan

Ok, i'll look into it.

dnauck avatar Feb 04 '16 15:02 dnauck