[Vuejs]-Chosen (chosen-js): How to cancel selected with multiple selector

0👍

It was realized with the following code.

$('.select-company').chosen({
    width: width,
}).change(function(ev, result) {
    if (result.selected !== 'target value') {
        return;
    }

    let val = $('.my-selector').val();
    for (let i = 0; i < val.length; ++i) {
        if (val[i] === result.selected) {
            val.splice(i, 1);
            --i;
        }
    }

    $('.my-selector').val(val);
    $('.my-selector').trigger('chosen:updated');
});

Leave a comment