Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clear angucomplete-alt after button click #60

Closed
smiderle opened this issue Oct 10, 2014 · 7 comments
Closed

clear angucomplete-alt after button click #60

smiderle opened this issue Oct 10, 2014 · 7 comments

Comments

@smiderle
Copy link

Hi. How do to clear the content of the input angucomplete-alt (scope.searchStr),by controller, for example, when the user click a button?

@ghost
Copy link

ghost commented Oct 10, 2014

Doesn't look like you can.

It would be nice if you could pass a function from your controller into the clear-selected or some other attribute and have angucomplete add a listener to that function to clear the string when the function is called.

@ghost
Copy link

ghost commented Oct 10, 2014

I created a Pull Request for this:
#61

You can use the branch on my fork in the meantime if you like in your bower.json:
"angucomplete-alt": "https://github.com/Leocrest/angucomplete-alt.git#feat/clear"

Branch can be found here:
https://github.com/Leocrest/angucomplete-alt/tree/feat/clear

Basically in your controller if you have a button calling a function called addSelected you can do something like:

$scope.addSelected = function (role) {
          //Complete app specific logic
          ...
          //Then
          $rootScope.$broadcast('angucomplete-alt:clearSearch');
      };

@ghost
Copy link

ghost commented Oct 10, 2014

Quick note: This approach will clear the inputs on ALL angucomplete fields. So if you have more than one on a view this may not be exactly what you want. In my case there is only one angucomplete on the view so it doesn't matter.

@smiderle
Copy link
Author

Thanks for the answer. But I have more than one on a view. I'll try something similar.

@smiderle
Copy link
Author

I made as small adjustment, and it worked fine with multiple directive in a view.

$rootScope.$broadcast('angucomplete-alt:clearSearch', { target: 'idAutocomplete' });

and in angucomplete-alt

scope.$on('angucomplete-alt:clearSearch', function (event, args) {
    if(scope.id == args.target){
      scope.searchStr = null;
      clearResults();
     }        
 });

Thanks.

@ghiden
Copy link
Owner

ghiden commented Oct 12, 2014

I think people want both clear all and individual options.
I'll add this feature based on @Leocrest #61

@ghiden ghiden closed this as completed Oct 13, 2014
@jlhffmn
Copy link

jlhffmn commented Jan 2, 2015

Note that the syntax has changed. See the description at the bottom of the angucomplete-alt home page:
$scope.$broadcast('angucomplete-alt:clearInput', 'autocomplete-1');

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants