Skip to content

Commit

Permalink
Fix bug with enumSource
Browse files Browse the repository at this point in the history
  • Loading branch information
jdorn committed Jul 3, 2015
1 parent 1097489 commit a07c2da
Showing 1 changed file with 44 additions and 42 deletions.
86 changes: 44 additions & 42 deletions src/editors/select.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,53 +221,55 @@ JSONEditor.defaults.editors.select = JSONEditor.AbstractEditor.extend({
items = vars[this.enumSource[i].source];
}

// Only use a predefined part of the array
if(this.enumSource[i].slice) {
items = Array.prototype.slice.apply(items,this.enumSource[i].slice);
}
// Filter the items
if(this.enumSource[i].filter) {
var new_items = [];
for(j=0; j<items.length; j++) {
if(this.enumSource[i].filter({i:j,item:items[j]})) new_items.push(items[j]);
}
items = new_items;
}

var item_titles = [];
var item_values = [];
for(j=0; j<items.length; j++) {
var item = items[j];

// Rendered value
if(this.enumSource[i].value) {
item_values[j] = this.enumSource[i].value({
i: j,
item: item
});
if(items) {
// Only use a predefined part of the array
if(this.enumSource[i].slice) {
items = Array.prototype.slice.apply(items,this.enumSource[i].slice);
}
// Use value directly
else {
item_values[j] = items[j];
// Filter the items
if(this.enumSource[i].filter) {
var new_items = [];
for(j=0; j<items.length; j++) {
if(this.enumSource[i].filter({i:j,item:items[j]})) new_items.push(items[j]);
}
items = new_items;
}

// Rendered title
if(this.enumSource[i].title) {
item_titles[j] = this.enumSource[i].title({
i: j,
item: item
});
}
// Use value as the title also
else {
item_titles[j] = item_values[j];
var item_titles = [];
var item_values = [];
for(j=0; j<items.length; j++) {
var item = items[j];

// Rendered value
if(this.enumSource[i].value) {
item_values[j] = this.enumSource[i].value({
i: j,
item: item
});
}
// Use value directly
else {
item_values[j] = items[j];
}

// Rendered title
if(this.enumSource[i].title) {
item_titles[j] = this.enumSource[i].title({
i: j,
item: item
});
}
// Use value as the title also
else {
item_titles[j] = item_values[j];
}
}

// TODO: sort

select_options = select_options.concat(item_values);
select_titles = select_titles.concat(item_titles);
}

// TODO: sort

select_options = select_options.concat(item_values);
select_titles = select_titles.concat(item_titles);
}
}

Expand Down

0 comments on commit a07c2da

Please sign in to comment.