ClickerMonkey / SemanticUI-Angular

Angular Directives for Semantic UI
http://clickermonkey.github.io/SemanticUI-Angular/examples/
MIT License
56 stars 28 forks source link

sm-dropdown on-change function called on scroll #34

Open ghost opened 6 years ago

ghost commented 6 years ago

Hello guys,

First, congratulations on the work you have provided and many thanks for the useful functionality you provide. There is some weird behavior with the on-change function callback.

I have the following usage of the sm-dropdown component:


<sm-dropdown
    autocentrum-select
    ng-if="searchElement.nivel === 0"
    ng-class="{
         'ng-highlighted':
         cautareService.model[category.id][searchElement.id] &&
         cautareService.model[category.id][searchElement.id].length
     }"
    class="fluid multiple search selection"
    model="cautareService.model[category.id][searchElement.id]"
    items="searchElement.valori"
    label="item.valoare"
    value="item"
    on-change="updateChildSearchElementValues(searchElement)"
    default-text="searchElement.nume"
    name="autocomplete-select-{{searchElement.id}}"
    settings="{useLabels: false, message: {count: searchElement.nume + ' - {count} selectate' }}">
</sm-dropdown>```

The on-change callback function is called multiple times when you change the select value (5-6 times) and also, the biggest issue is that it gets called on every scroll event.
ghost commented 6 years ago

From what I noticed the on-change is called incorrectly. So there it should be: on-change="updateChildSearchElementValues". I am now correctly setting up the on-change event but this is called multiple times. The following scenario happens:

  1. You select a value, it is triggered 2 times;
  2. Select 2nd option: triggered 4 times
  3. Select 3rd option: triggered 6 times

Basically with a new selection added, the callback returns n*2 (n is the number of selected items).

ghost commented 6 years ago

Is this repository followed anymore?

ClickerMonkey commented 6 years ago

Greetings Florinmtsc!

The on-change attribute is tied directly into the Semantic UI library and is not evaluated by this library. You should check your Semantic UI version and if you are up to date perhaps try to report the issue in the main SUI repository.

There are plans to eventually change to using the ngModel directive which would allow you to use the ngChange event. But I don't know when I'll get to that.

There are a few other odd issues with smDropdown depending on how you are using it (I've experienced them myself but no one has reported them yet) - and those issues would be addressed in the next version as well.

ghost commented 6 years ago

Thanks for your response. I'll try to implement the ngModel and create a pull request. Hopefully my time will allow this wish.