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({})
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.
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.
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.
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.
Try this :
$('select.dropdown').dropdown({placeholder:'Your placeholder'});
see Semantic UI (or Semantic UI CN for a Chinese version) for more info.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With