Skip to content

Commit

Permalink
Remove selectize from demo.html, tighten up resolver rules for select…
Browse files Browse the repository at this point in the history
…izeArray
  • Loading branch information
jdorn committed Sep 27, 2015
1 parent a85e590 commit 4c206c4
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 50 deletions.
36 changes: 0 additions & 36 deletions demo.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
<!-- placeholders for the theme switcher -->
<link rel='stylesheet' id='theme_stylesheet'>
<link rel='stylesheet' id='icon_stylesheet'>
<link rel='stylesheet' id='selectize_stylesheet'>

<style>[class*="foundicon-"] {font-family: GeneralFoundicons;font-style: normal;}</style>
<script src='dist/jsoneditor.js'></script>
Expand Down Expand Up @@ -83,9 +82,6 @@ <h2>Options</h2>
<option value='never'>Never</option>
</select>
</div>
<div>
<button class='btn btn-primary' id='selectize_support'>Enable Selectize Support</button>
</div>
<div>
<label>Boolean options</label>
<select multiple size=9 id='boolean_options' style='width: 100%;' class='form-control'>
Expand Down Expand Up @@ -193,13 +189,6 @@ <h2>Code</h2>
type: "string",
enum: ["male", "female"]
},
interests: {
type: "array",
items: {
type: "string"
},
default: ["Squash", "Badminton", "Rugby"]
},
location: {
type: "object",
title: "Location",
Expand Down Expand Up @@ -391,14 +380,6 @@ <h2>Code</h2>
if(!no_reload) reload(true);
};

function loadScript(path, onload) {
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = path;
script.onload = onload
document.getElementsByTagName('head')[0].appendChild(script);
}

// Change listeners for options
document.getElementById('theme_switcher').addEventListener('change',function() {
setTheme(this.value);
Expand All @@ -414,23 +395,6 @@ <h2>Code</h2>
JSONEditor.defaults.options.show_errors = this.value;
reload(true);
});
document.getElementById('selectize_support').addEventListener('click',function() {
var button = this;

JSONEditor.plugins.selectize.enable = true;

if (!window.jQuery) {
document.getElementById('selectize_stylesheet').href = '//cdnjs.cloudflare.com/ajax/libs/selectize.js/0.12.1/css/selectize.bootstrap3.css';

// jQuery must be loaded before Selectize can be safely loaded
loadScript('//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.4/jquery.min.js', function() {
loadScript('//cdnjs.cloudflare.com/ajax/libs/selectize.js/0.12.1/js/standalone/selectize.js', function() {
button.setAttribute('disabled', true)
reload(true);
})
});
}
});
document.getElementById('boolean_options').addEventListener('change',function() {
refreshBooleanOptions();
});
Expand Down
7 changes: 2 additions & 5 deletions examples/selectize.html
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,11 @@ <h1>JSON Editor Selectize Integration Example</h1>
},
possibleFonts: {
type: "array",
format: 'table',
uniqueItems: true,
items: {
type: "string"
},
default: ["Arial","Times","Helvetica","Comic Sans"],
options: {
collapsed: true
}
default: ["Arial","Times","Helvetica","Comic Sans"]
}
}
},
Expand Down
19 changes: 10 additions & 9 deletions src/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,20 +241,21 @@ JSONEditor.defaults.resolvers.unshift(function(schema) {
}
}
});
// Use the 'multiselect' editor for arrays of enumerated strings/numbers/integers
// Specialized editors for arrays of strings
JSONEditor.defaults.resolvers.unshift(function(schema) {
if(schema.type === "array" && schema.items && !(Array.isArray(schema.items)) && schema.uniqueItems && schema.items["enum"] && ['string','number','integer'].indexOf(schema.items.type) >= 0) {
return 'multiselect';
if(schema.type === "array" && schema.items && !(Array.isArray(schema.items)) && schema.uniqueItems && ['string','number','integer'].indexOf(schema.items.type) >= 0) {
// For enumerated strings, number, or integers
if(schema.items.enum) {
return 'multiselect';
}
// For non-enumerated strings (tag editor)
else if(JSONEditor.plugins.selectize.enable && schema.items.type === "string") {
return 'arraySelectize';
}
}
});
// Use the multiple editor for schemas with `oneOf` set
JSONEditor.defaults.resolvers.unshift(function(schema) {
// If this schema uses `oneOf`
if(schema.oneOf) return "multiple";
});
// If enabled, use Selectize for arrays
JSONEditor.defaults.resolvers.unshift(function(schema) {
if(schema.type === "array" && JSONEditor.plugins.selectize.enable) {
return 'arraySelectize';
}
});

0 comments on commit 4c206c4

Please sign in to comment.