Skip to content

Commit

Permalink
multiselect paramter for content structure
Browse files Browse the repository at this point in the history
  • Loading branch information
EdwardBock committed Oct 24, 2019
1 parent aa11d97 commit 5e2faaa
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions js/app/views/EditorWidgets/select.js
Expand Up @@ -11,11 +11,26 @@ boxEditorControls['select']=GridBackbone.View.extend({

},
render:function(){
var html="<label>"+this.model.structure.label+"</label><select>";
var self=this;
_.each(this.model.structure.selections,function(elem){

const structure = this.model.structure;
const container = this.model.container;

const isMultiple = (typeof structure.multiple !== typeof undefined && structure.multiple);
const values = container[structure.key];
const hasMultipleValues = (typeof values === typeof []);
const selections = structure.selections;

const multiple = (isMultiple)? "multiple='multiple'": "";
const size = (!isMultiple || selections.size < 8)? "": (selections.length < 12)? "size='6'": "size='8'";

let html="<label>"+this.model.structure.label+"</label><select "+multiple+" "+size+">";
_.each(selections,function(elem){
var selected="";
if(self.model.container[self.model.structure.key]==elem.key)selected="selected";
if(
(!hasMultipleValues && values === elem.key)
||
(hasMultipleValues && _.indexOf(values, elem.key) > -1)
) selected="selected";
html+="<option "+selected+" value='"+elem.key+"'>"+elem.text+"</option>";
});
html=html+"</select>";
Expand Down

0 comments on commit 5e2faaa

Please sign in to comment.