Semantic-ui: dropdown : onchange not be triggered when "set selected"

Created on 2 Dec 2014  路  7Comments  路  Source: Semantic-Org/Semantic-UI

"set selected" worked, but onchange not be triggered. Should not?

Enhancement

Most helpful comment

Am I the only one who needs OnChange not to be triggered when 'set selected' is called?

On load I want to prepopulate the dropdown with selections from the server (using 'set selected') and only call the OnChange when the user manually selects an item (so it can be added to the server db too).

A possibility would be for the OnChange to get an additional parameter to define whether is called from 'set selected' or from user action.

All 7 comments

This is similar behavior to jQuery - it is programmer's responsibility to call triggers (jQuery('.foo').trigger('change')).

I'm here to please. :smiley_cat:

Adding onChange to set selected in 1.1.0

Am I the only one who needs OnChange not to be triggered when 'set selected' is called?

On load I want to prepopulate the dropdown with selections from the server (using 'set selected') and only call the OnChange when the user manually selects an item (so it can be added to the server db too).

A possibility would be for the OnChange to get an additional parameter to define whether is called from 'set selected' or from user action.

set selected could have a third parameter "silent", to prevent triggering onChange which is set to false by default. This would be a non-breaking change:

$elem.dropdown('set selected', value, silent);

Example for a silent value change:
$elem.dropdown('set selected', [23, 33, 119], true);

Example for a regular value change triggering onChange (as to now):
$elem.dropdown('set selected', [23, 33, 119]);

+1 @activeperception @achimkoellner

@jlukic is this possible?

@xxRockOnxx You might be able to achieve this by changing dropdown module settings: http://semantic-ui.com/modules/dropdown.html#/settings

Looking at the code that introduced the onChange call you can see all it does it calls $.proxy towards settings.onChange.

I'd say it is a mistake to add it in the first place (in my opinion you should follow the path of least side effects) and it did introduce a breaking change, since onChange was never called before, and now it does without asking.

I do have a workaround but having silent parameter would be good.
I instead find the hidden input and set the value to empty. Same thing to the .text

Was this page helpful?
0 / 5 - 0 ratings

Related issues

davialexandre picture davialexandre  路  3Comments

deneuxa picture deneuxa  路  3Comments

mixerp picture mixerp  路  3Comments

ghost picture ghost  路  3Comments

miguelmota picture miguelmota  路  3Comments