Semantic-ui: Dropdown does not respond to value changed by javascript

Created on 2 Mar 2017  路  8Comments  路  Source: Semantic-Org/Semantic-UI

See: http://jsfiddle.net/haq53nkf/2/

Huge problem for people using vuejs and similar systems where values are managed through JS.

Usage Question

All 8 comments

Have a look at the Dropdown behaviours here: http://semantic-ui.com/modules/dropdown.html#/usage. set selected(value) should be your friend.

Unfortunately, set selected is not very friendly with variable binding with libraries like vuejs.

Could you elaborate on that comment? I don't understand it :-)

Here is a working fiddle: http://jsfiddle.net/2vdgwrty/

With libraries like vuejs, the input values are bind directly to the element.

You don't execute a method to set the value. You set a "model" variable on the input element and when the variable changes, the input is automatically updated. You could "watch" a variable manually and execute set selected every time it's updated, but that's not how it should work.

Information: https://vuejs.org/v2/guide/forms.html

Other libraries also work like this.

Semantic ui should not require the value to be set using a custom method. Instead, it should be watching the hidden input and triggering the the set selected method internally automatically.

Hi @komirad, this is an issue with Vue lifecycle, not SUI, and jQuery doesn鈥檛 play well with JavaScript frameworks in general. There were a lot of similar issues when I was doing a Vue 2/SUI project, but unless someone will do a Vue integration, I don鈥檛 think it makes sense to overengineer the jQuery version.

Instead, it should be watching the hidden input and triggering the the set selected method internally automatically.

If this is what you need for integrating vue and sui, then do it ;-)

@Banandrew Since SUI is the one generating the hidden input(to replace the select element), shouldn't SUI also watch for changes in the hidden input? Not doing that means that every other library has to have custom code to work with SUI dropdowns.

Not sure if it's a jQuery problem. I am guessing coding in vanilla js, I would also be selecting using [name=] attribute to change the value. (Or setting the selected attribute on <option> but that has been replaced.)

@komirad SUI doesn鈥檛 replace select element, and hides it instead, but that doesn鈥檛 matter鈥擨 understand what you鈥檙e saying, and it does make a lot of sense to me; when you use jQuery libraries with JavaScript frameworks, extra code is, unfortunately, inevitable.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ghost picture ghost  路  3Comments

arj-196 picture arj-196  路  3Comments

guilhermeblanco picture guilhermeblanco  路  3Comments

zhaoyao91 picture zhaoyao91  路  3Comments

iPaoo picture iPaoo  路  3Comments