Search code examples
javascriptjquerymulti-selectsumoselect.js

Sumoselect with Ok/Cancel buttons remember selected values after click away


I am using sumoselect on my web.

Case #1:

Default behavior in select input like on example page with title 'Multiple select' is - open select input, select any items and click anywhere else = close select input and my selected items are still selected (after reopen select input).

Case #2

I want have buttons ok/cancel - like on example page with title 'Show ok cancel in multiselect', but if i do this then behavior is changed. If i open select input, select any items and click anywhere else = close select input but items are not selected farthest... I must click on button OK for remembering my choice

Q: How to achieve behavior like in case #1 with buttons ok/cancel? Select some items an after click anywhere else - close select input and my choices still be here?

Sub question: How i can create some event on click ok/cancel button? ex. click on cancel and have something like $('this').sumo.unSelectAll();

EDIT: if i set

`triggerChangeCombined: false`

pick some items and click away (for close select) in 'placeholder' place i will see my selection, but after reopen select input items aren't selected.


Solution

  • Regarding the initial requirement to have the selected options remembered in the ok/Cancel configuration, the answer is that as the code stands you cannot.

    Why? Because in the source code, where a click outside the dropdown is detected, there is a line that says 'if we are in ok-cancel mode then click the cancel button'.

    if (settings.okCancelInMulti)O._cnbtn();
    

    You would have to create a special version / fork of the code to remove this line and achieve your desired behaviour.