Dropdown disable option

Support General Dropdown disable option

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #13843
    woorisewoorise
    Participant

    I use two select_advanced fields and when I select an option in the first dropdown I want to disabled it from the second dropdown.

    I use the following code. The disabled attribute added successfully but the option isn't disabled.

    
    (function($) {
    
        $('#_language_pairs_from').on('change', function() {
            var selectVal = $(this).val();
            $('#_language_pairs_to option[value="'+selectVal+'"]').prop('disabled', true);
        });
    
    })( jQuery );
    
    #13867
    Anh TranAnh Tran
    Keymaster

    Hi,

    I think you need to use select2 API. Your code seems to work only for normal select.

    #13987
    woorisewoorise
    Participant

    I am using the exact same code as in the jsfiddle http://jsfiddle.net/u3tq89wg/ in a clean installation but it works only the first time. It doesn't updated after I open the second dropdown. I don't get any console errors.

    Can you please give me a working example?

    #13999
    Anh TranAnh Tran
    Keymaster

    I made a modification to that script, here is a working version: https://ghostbin.com/paste/tqqof

    #14013
    woorisewoorise
    Participant

    Thank you very much! Now it works!

    I notice that we destroy the select and initialize it again. Doing this we lose the initial options. Is there any way to automatically set the initial options?

    #14020
    Anh TranAnh Tran
    Keymaster

    Ah, when initialize the select2, you can get options via data-options and pass it to the initializer:

    var options = $s2.data( 'options' );
    $s2.select2( options );
Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.