Skip to content

feat(autocomplete): fire "onSelected" event when the user select an option #3645

Closed

Description

@jefersonestevo

Bug, feature request, or proposal:

featur

What is the expected behavior?

Create a new output (onSelected?) that fires an event when the user select an option from the autocomplete

What is the current behavior?

There is no way to know when the user has selected an option from the autocomplete

What is the use-case or motivation for changing an existing behavior?

I have some cases that I need to update some fields based on the user selected option and would be nice if I can get a callback from the component itself

Activity

  1. added
    feature
    on Mar 16, 2017
  2. added
    P3
    on Mar 16, 2017
  3. willshowell commented on Mar 17, 2017

    @willshowell
    Contributor

    There is an optionSelections Observable on the autocomplete component. Does that accomplish what you need?

    /** Stream of autocomplete option selections. */
    get optionSelections(): Observable<MdOptionSelectionChange> {
      return Observable.merge(...this.autocomplete.options.map(option => option.onSelectionChange));
    }

    From https://github.com/angular/material2/blob/master/src/lib/autocomplete/autocomplete-trigger.ts#L160

  4. jefersonestevo commented on Mar 17, 2017

    @jefersonestevo
    ContributorAuthor

    I haven't tested, but I think that this observer would work for what I'm needing. But the point is that it'll be nicer if we can just create a listener on our class and use the event listener right from the html page.

    <md-autocomplete (onSelected)="myCallbackFunction($event)" .....

  5. willshowell commented on Mar 17, 2017

    @willshowell
    Contributor

    You can also wire up a listener to md-option if you'd like. See #3576.

    Note: the api for md-option changes as of #2722 to support multi select (in case you're using the latest builds)

  6. jefersonestevo commented on Mar 17, 2017

    @jefersonestevo
    ContributorAuthor

    Great! I can use that for now. Thanks @willshowell

  7. jefersonestevo commented on Mar 29, 2017

    @jefersonestevo
    ContributorAuthor

    @kara do you think that "onSelected" will be a good name for the output event? If so, I can create a PR with this change

  8. wulfsberg commented on Apr 18, 2017

    @wulfsberg

    Just came across this randomly, and wanted to mentioned that the official styleguide discourages the "on-" prefix for output events.
    https://angular.io/docs/ts/latest/guide/style-guide.html#!#05-16

  9. added a commit that references this issue on Apr 20, 2017
    21e4ae2
  10. liri2006 commented on Jul 2, 2017

    @liri2006

    +1

  11. added 2 commits that reference this issue on Aug 20, 2017
    2b78839
    58d161a
  12. added a commit that references this issue on Aug 23, 2017
    2dd5c7c
  13. angular-automatic-lock-bot commented on Sep 6, 2019

    @angular-automatic-lock-bot

    This issue has been automatically locked due to inactivity.
    Please file a new issue if you are encountering a similar or related problem.

    Read more about our automatic conversation locking policy.

    This action has been performed automatically by a bot.

  14. locked and limited conversation to collaborators on Sep 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

P3feature

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions