Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions examples/selectize.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,20 @@ <h1>JSON Editor Selectize Integration Example</h1>
type: "integer",
enum: [10,11,12,14,16,18,20,22,24,36,48,60,72,100],
default: 24,
options: {
// Override defaullt options
selectize_options: {
create: true
}
}
},
color: {
type: "string",
enum: ["black","red","green","blue","yellow","orange","purple","brown","white","cyan","maagenta"],
enum: ["black","red","green","blue","yellow","orange","purple","brown","white","cyan","magenta"],
options: {
// Override defaullt options
selectize_options: {
create: true,
create: false,
sortField: 'text'
}
}
Expand All @@ -49,6 +55,13 @@ <h1>JSON Editor Selectize Integration Example</h1>
watch: {
"possible_fonts": "root.possibleFonts"
},
options: {
// Override defaullt options
selectize_options: {
create: false,
sortField: 'text'
}
}
},
weight: {
type: "string",
Expand Down
15 changes: 13 additions & 2 deletions src/editors/selectize.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,14 +169,16 @@ JSONEditor.defaults.editors.selectize = JSONEditor.AbstractEditor.extend({
this.value = this.enum_values[0];
},
onInputChange: function() {
//console.log("onInputChange");
var val = this.input.value;

var sanitized = val;
if(this.enum_options.indexOf(val) === -1) {
sanitized = this.enum_options[0];
}

this.value = this.enum_values[this.enum_options.indexOf(val)];
//this.value = this.enum_values[this.enum_options.indexOf(val)];
this.value = val;
this.onChange(true);
},
setupSelectize: function() {
Expand All @@ -187,7 +189,8 @@ JSONEditor.defaults.editors.selectize = JSONEditor.AbstractEditor.extend({
if(this.schema.options && this.schema.options.selectize_options) options = $extend(options,this.schema.options.selectize_options);
this.selectize = window.jQuery(this.input).selectize($extend(options,
{
create: true,
// set the create option to true by default, or to the user specified value if defined
create: ( options.create === undefined ? true : options.create),
onChange : function() {
self.onInputChange();
}
Expand Down Expand Up @@ -273,6 +276,14 @@ JSONEditor.defaults.editors.selectize = JSONEditor.AbstractEditor.extend({

var prev_value = this.value;

// Check to see if this item is in the list
// Note: We have to skip empty string for watch lists to work properly
if ((prev_value !== undefined) && (prev_value !== "") && (select_options.indexOf(prev_value) === -1)) {
// item is not in the list. Add it.
select_options = select_options.concat(prev_value);
select_titles = select_titles.concat(prev_value);
}

this.theme.setSelectOptions(this.input, select_options, select_titles);
this.enum_options = select_options;
this.enum_display = select_titles;
Expand Down