Skip to content
This repository has been archived by the owner on Dec 16, 2019. It is now read-only.

Please provide an example with event handlers #39

Closed
lindamarieb opened this issue Nov 7, 2014 · 4 comments
Closed

Please provide an example with event handlers #39

lindamarieb opened this issue Nov 7, 2014 · 4 comments

Comments

@lindamarieb
Copy link

I've tried using onItemSelect event but it never gets called. Here are my options:

$scope.multiSelectSettings = {
        enableSearch: true, 
        displayProp: 'name',
        scrollableHeight: '200px',
        scrollable: true,
        buttonClasses: 'btn btn-entity-select',
        smartButtonMaxItems: 10,
        dynamicTitle: true,
        externalIdProp: '',
        events: {
            onItemSelect: function (item) {
                console.log('selected: '+item);
            }
        }
    };
@PawelDecowski
Copy link

The events object should be an attribute of the HTML element. For example:

<div ng-dropdown-multiselect
     options="regions_options"
     selected-model="regions_selected"
     events="{ onItemSelect: function(item) { console.log(item) } }">

Of course I’d advise against embedding the function’s body in the template. Instead you should define it in the controller and reference it by name in the template.

@sharvesh
Copy link

Hi,

I'm also new to this and this worked for me.
Hope this helps

          $scope.yourEvents = {
                     onInitDone: function(item) {
                              console.log(item);
                         },
                     onItemDeselect: function(item) {
                              console.log(item);
                        }
             };
<div ng-dropdown-multiselect="" options="YourData" events="yourEvents" 
     selected-model="YourModel" extra-settings="yourSettings">
</div>

@mnemanja
Copy link

You can inline it like this

<div ng-dropdown-multiselect
     options="regions_options"
     selected-model="regions_selected"
     events="{ onItemSelect: someFunction }">

or even have multiple callbacks inline by extending the events object, like so:

    events="{ onItemSelect: someFunction, onInitDone: functionToBeExecutedOnInitDone }"

Notice that we are referencing the function, not calling it. someFunction - without ().

What I would like to know is how to get more data from the element. The onItemSelect callback provides the option's ID, nothing else.
What would be nice is way to provide the element's ID, not just the element option's ID.

@pkempenaers
Copy link
Collaborator

Using events is documented. Setting externalIdProp to "" will pass full items to events. (this should probably be documented)

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

No branches or pull requests

5 participants