سؤال

I have the following dropdown using Semantic UI:

<div class="ui selection dropdown select-language">
    <input name="language" type="hidden" value="fr-FR">
    <div class="text">French</div>
    <i class="dropdown icon"></i>
    <div class="menu ui transition hidden">
        <div class="item" data-value="en-US">English</div>
        <div class="item active" data-value="fr-FR">French</div>
    </div>
</div>

And in the jQuery side I init it:

$(".select-language").dropdown()

How can I add the change handler?

The only thing related to this I found in the documentation is:

onChange(value, text)

Context: Dropdown

Is called after a dropdown item is selected. receives the name and value of selection.

This sounds a little confusing for me. How can I use it?

JSFIDDLE

هل كانت مفيدة؟

المحلول

Actually, there are three ways to bind the event:

// globally inherited on init
$.fn.dropdown.onChange = function(){...};

// during init
$('.myDropdown').dropdown({
 onChange: function() {...}
});

// after init
$('.myDropdown').dropdown('setting', 'onChange', function(){...});

نصائح أخرى

It seems that onChange setting can be added when creating the dropdown:

$(".select-language").dropdown({
    onChange: function (val) {
        alert(val);
    }
});

JSFIDDLE

    jQuery('.ui.ekstensi.fluid.dropdown').dropdown('setting','onAdd',function (val,text,choice) {

    alert(choice);
    }).dropdown('setting','onRemove',function (removedValue, removedText, removedChoice) {
    //your action here
    alert(removedValue);

    });

JSFIDDLE

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top