angular-advanced-searchbox
angular-advanced-searchbox copied to clipboard
Submit Search.
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?
Same for "delete". In my controller, how do i know that the search has been cleared.
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.
Thanks for the response. Here is my example:
- Lets say i have 1 parameter called as "User".
- Now i click on the search box, then i click on "User" to apply it.
- 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?
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.
To receive internal status changes we need to implement some events you can watch on. Maybe this is what you need.
Yes, thats correct.
I'll investigate if we go for events or callbacks.
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?
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
Upss,
I just saw that the ng-show is already replaced with ng-if in the new version of directive
+1 for having a callback/event when the searchbar changes focus
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.
Ok, i'll look into it.