Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Semantic UI: Dropdown default/placeholder value issue

I'm working on creating a html form using 'Semantic UI' framework. While I'm using a normal select item for a dropdown/select list, I'm styling it using Semantic UI. Everything works fine, but once I select a value from the dropdown, I can't deselect the option/value as an end user.

Suppose in this FIDDLE , if I select 'male', and again want to de-select the option and show the placeholder/default text 'Gender', I'm not able to. Can someone help me figure out a way to make the select work as a regular html select item rather than a dropdown ?

HTML Code

<div class="field">
            <label style="width: 250px">Select a Gender</label> <select
                name="skills" class="ui fluid dropdown">
                <option value="">Gender</option>
                <option value="Male">Male</option>
                <option value="Female">Female</option>
            </select>
</div>

JavaScript Code

$(".ui.fluid.dropdown").dropdown({})
like image 431
Phanikanth Avatar asked Sep 03 '15 17:09

Phanikanth


People also ask

Why does it default to the first item in the dropdown?

It currently defaults to the first item because it has no option with an empty value. Here it is revealed: I believe the fix is as simple as adding an always present option with a value='' to the hidden select in Dropdown.js.

Is there an empty value for the Dom in the dropdown?

Confirmed bug, thanks. There is a hidden select in the Dropdown that holds the value for the DOM. It currently defaults to the first item because it has no option with an empty value. Here it is revealed: I believe the fix is as simple as adding an always present option with a value='' to the hidden select in Dropdown.js.

What does selected mean in Semantic-UI?

This is a little confusing at first, but in Semantic-UI selected means the item is highlighted but not active. The selected item changes as you press the up and down arrows or perform a search. However, the active item (s) are what comprise the value.

How do I change the default delimiter for dropdown items?

The default is "," but this can be changed by adjusting the delimiter setting. Dropdowns have multiple built-in actions that can occur on item selection. You can specify a built-in action by passing its name to settings.action or pass a custom function that performs an action. To specify a different built in action, simply specify the name.


2 Answers

Try this :

$('select.dropdown').dropdown({placeholder:'Your placeholder'});

see Semantic UI (or Semantic UI CN for a Chinese version) for more info.

like image 138
Alsmile Avatar answered Sep 27 '22 23:09

Alsmile


In the classic HTML <select> element, it treats your empty valued <option value="">Gender</option> as another dropdown menu item.

However, Semantic UI uses the empty valued <option> as the placeholder text. If you want Gender as a selectable option, it should really be another item that is independent of your placeholder text.

If you want the ability to clear the selection, I think there are better UX paradigms to handle this. For example, you could have an external clear selection button which calls:

$('.ui.fluid.dropdown').dropdown('clear')

Another more streamlined option might be to use the multi-selection dropdown, and limit the maxSelections = 1, the first example from the examples page. That way the user gets an impression that they have selected something, and to clear the selection they use an element within the same dropdown container.

like image 35
J3Y Avatar answered Sep 28 '22 00:09

J3Y