Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dropdown clear option semantic-ui

I've encountered a problem when trying to implement 2 dropdowns in semantic-ui.

What I want to happen is that when I change the selected item in the first dropdown the second dropdown will be automatically be cleared from its pervious selection (this is the first step in implementing an automatic change to the content of the second dropdown).

I've created a simpler version containing 2 dropdowns and a clear button in JS bin : here.

The code:

var $one = $('#one'),
    $two = $('#two');

$two.dropdown();
$one.dropdown({
    onChange :function(val) {
        $two.dropdown('clear');
    }
});

$('.button').on('click', function() {
    $('#two').dropdown('clear');  
});

Here I've encountered multiple problems:

The first problem I encountered was that the clear button won't clear both dropdowns unless both dropdowns are only initialised and no other settings added in the initialisation (i.e $(".ui.dropdown").dropdown()).

The second problem is that in the provided code the a dropdown will be cleared (only the second dropdown will be cleared for some reason, and not the first) only if the selector for the clear button will be $(".ui.dropdown) , if I use $("#one")/$("#two") the button won't clear the dropdown.

And the third problem , is that when a change occurs in the first dropdown the second dropdown is not being cleared , which is my ultimate goal.

Any thoughts or suggestions will be greatly appreciated.

like image 705
user3040942 Avatar asked Aug 27 '15 14:08

user3040942


People also ask

How do I disable semantic UI dropdown?

Users can show the dropdown in disabled state and do not grant him to change the state. Semantic UI Dropdown Disabled State Class: disabled: This class is used to set the dropdown status to disabled.

Which UI component allows used to select an item from dropdown menu?

The dropdown list we have used here may appear similar to the dropdowns we have used in our jQuery menu component. The key difference with the dropdown list component is that the currently selected item is always exposed and the purpose is to indicate that the user can toggle between options.

What is dropdown in UI?

A dropdown menu is a design pattern letting you display a list of contents, navigation points, and functions without flooding the user with many options simultaneously.

How do I add a search drop down in HTML?

Use any element to open the dropdown menu, e.g. a <button>, <a> or <p> element. Use a container element (like <div>) to create the dropdown menu and add the dropdown links inside it. Wrap a <div> element around the button and the <div> to position the dropdown menu correctly with CSS.


2 Answers

$(document).ready(function () {
            $("#super_type").dropdown({
                onChange: function (val) {
                    $('#subtype_list').dropdown('clear');
     });
});
like image 54
Ritesh Kumar Avatar answered Oct 21 '22 17:10

Ritesh Kumar


This is the best and easy solution provided by semantic UI. $('.ui.dropdown').dropdown({ "clearable": true }); By default the value of clearable setting is false.

like image 23
Kshitij Avatar answered Oct 21 '22 18:10

Kshitij