2016-11-17 2 views
1

다중 값 선택 상자에 Select2 (https://select2.github.io/examples.html)를 사용하면 드롭 다운에서 선택한 값을 토글 할 수 있습니다. 이 문제를 방지 할 수있는 방법이 있습니까? 그래서 당신은 단지 옆에있는 X를 클릭하여 선택한 항목을 제거 할 수 있습니다.드롭 다운에서 선택한 항목을 클릭 할 때 선택 항목을 토글하지 않습니다.

모든 도움을 주시면 감사하겠습니다.

+0

를 사용, 자세한 내용은 https://select2.github.io/examples.html#programmatic-control 참조 이것에 대해 http://jsfiddle.net/ishanbakshi/fyhsz9ra/ –

+0

나는 ju라고 말할 것이다. 선택한 옵션을 선택한 후에 옵션 목록에서 선택한 옵션을 제거하십시오. – gkb

+0

이 경우에는 드롭 다운에 머물러 있지만 토글 기능은 필요하지 않습니다. – nikoka

답변

2

당신은 unselecting 이벤트를 사용할 수 있습니다

$(".js-source-states").select2() 
    .on("select2:unselecting", function (e) { 
    // make sure we are on the list and not within input box 
    if (e.params.args.originalEvent.currentTarget.nodeName === 'LI') { 
     e.preventDefault(); 
    } 
    } 
); 

plunker : http://plnkr.co/edit/f8w97dSykPmbCZkN65JA?p=preview

당신이 선택 닫으려는 경우, 찾고 $example.select2("close"); (https://select2.github.io/examples.html#programmatic)