Commit 99de3244 authored by Bas Lijnse's avatar Bas Lijnse

Merge branch '397-dont-use-click-even-for-dropdowns-and-checkgroups' into 'master'

Use change event on multiple select box instead of click events on individual options

Closes #397

See merge request !435
parents 59b9d5d3 440c354a
Pipeline #43656 passed with stage
in 9 minutes and 33 seconds
...@@ -59,13 +59,21 @@ itasks.Dropdown = class extends itasks.Selector { ...@@ -59,13 +59,21 @@ itasks.Dropdown = class extends itasks.Selector {
me.setOptions(me.attributes.options); me.setOptions(me.attributes.options);
//If the selection is a single one, a single handler on the select if (!el.disabled){
//suffices if (me.attributes.multiple){
if(!me.attributes.multiple && !el.disabled){ el.addEventListener('change',function(e) {
el.addEventListener('change',function(e) { me.attributes.value=[];
me.select(e.target.value === '' ? [] : [parseInt(e.target.value)]); for (var i=0; i<el.options.length; i++)
me.doEditEvent(me.attributes.taskId,me.attributes.editorId,me.attributes.value); if (el.options[i].selected)
}); me.attributes.value.push(parseInt(el.options[i].value));
me.doEditEvent(me.attributes.taskId,me.attributes.editorId,me.attributes.value);
});
} else {
el.addEventListener('change',function(e) {
me.select(e.target.value === '' ? [] : [parseInt(e.target.value)]);
me.doEditEvent(me.attributes.taskId,me.attributes.editorId,me.attributes.value);
});
}
} }
} }
selectInDOM(el,selected) { selectInDOM(el,selected) {
...@@ -117,17 +125,7 @@ itasks.Dropdown = class extends itasks.Selector { ...@@ -117,17 +125,7 @@ itasks.Dropdown = class extends itasks.Selector {
} }
curParentEl.appendChild(optionEl); curParentEl.appendChild(optionEl);
option.domEl = optionEl; option.domEl = optionEl;
},me);
//Only if the selection is a multiple selection we place handlers
//on every element
if(me.attributes.multiple && !el.disabled){
option.domEl.addEventListener('click',function(e) {
me.select([option.id], me.attributes.multiple && (e.metaKey || e.ctrlKey));
me.doEditEvent(me.attributes.taskId,me.attributes.editorId,me.attributes.value);
e.preventDefault();
});
}
},me);
} }
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment