selectize.html 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8" />
  5. <title>JSON Editor Selectize Integration Example</title>
  6. <script src="https://cdn.jsdelivr.net/npm/@json-editor/json-editor/dist/jsoneditor.min.js"></script>
  7. <script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
  8. <script src="//cdnjs.cloudflare.com/ajax/libs/selectize.js/0.12.1/js/standalone/selectize.js"></script>
  9. <link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/selectize.js/0.12.1/css/selectize.bootstrap3.css">
  10. </head>
  11. <body>
  12. <h1>JSON Editor Selectize Integration Example</h1>
  13. <p style='margin-bottom:20px;'>This example demonstrates JSONEditor's integration with Selectize</p>
  14. <div id='editor_holder'></div>
  15. <button id='submit'>Submit (console.log)</button>
  16. <script>
  17. // Global selectize options
  18. JSONEditor.plugins.selectize.enable = true;
  19. // Initialize the editor with a JSON schema
  20. var editor = new JSONEditor(document.getElementById('editor_holder'),{
  21. schema: {
  22. type: "object",
  23. title: "Text",
  24. required: ["fontSize","color","font","weight","possibleFonts"],
  25. properties: {
  26. fontSize: {
  27. type: "integer",
  28. enum: [10,11,12,14,16,18,20,22,24,36,48,60,72,100],
  29. default: 24,
  30. options: {
  31. // Override defaullt options
  32. selectize_options: {
  33. create: true
  34. }
  35. }
  36. },
  37. color: {
  38. type: "string",
  39. enum: ["black","red","green","blue","yellow","orange","purple","brown","white","cyan","magenta"],
  40. options: {
  41. // Override defaullt options
  42. selectize_options: {
  43. create: false,
  44. sortField: 'text'
  45. }
  46. }
  47. },
  48. font: {
  49. type: "string",
  50. enumSource: "possible_fonts",
  51. watch: {
  52. "possible_fonts": "root.possibleFonts"
  53. },
  54. options: {
  55. // Override defaullt options
  56. selectize_options: {
  57. create: false,
  58. sortField: 'text'
  59. }
  60. }
  61. },
  62. weight: {
  63. type: "string",
  64. enum: ["normal","bold","bolder","lighter"],
  65. options: {
  66. enum_titles: ["Normal (400)","Bold (700)","Bolder (900)","Lighter (200)"]
  67. }
  68. },
  69. possibleFonts: {
  70. type: "array",
  71. uniqueItems: true,
  72. items: {
  73. type: "string"
  74. },
  75. default: ["Arial","Times","Helvetica","Comic Sans"]
  76. }
  77. }
  78. },
  79. startval: {
  80. color: "red"
  81. }
  82. });
  83. // Hook up the submit button to log to the console
  84. document.getElementById('submit').addEventListener('click',function() {
  85. // Get the value from the editor
  86. console.log(editor.getValue());
  87. });
  88. </script>
  89. </body>
  90. </html>