basic.html 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8" />
  5. <title>Basic JSON Editor Example</title>
  6. <script src="https://cdn.jsdelivr.net/npm/@json-editor/json-editor/dist/jsoneditor.min.js"></script>
  7. </head>
  8. <body>
  9. <h1>Basic JSON Editor Example</h1>
  10. <div id='editor_holder'></div>
  11. <button id='submit'>Submit (console.log)</button>
  12. <script>
  13. // Initialize the editor with a JSON schema
  14. var editor = new JSONEditor(document.getElementById('editor_holder'),{
  15. schema: {
  16. type: "object",
  17. title: "Car",
  18. properties: {
  19. make: {
  20. type: "string",
  21. enum: [
  22. "Toyota",
  23. "BMW",
  24. "Honda",
  25. "Ford",
  26. "Chevy",
  27. "VW"
  28. ]
  29. },
  30. model: {
  31. type: "string"
  32. },
  33. year: {
  34. type: "integer",
  35. enum: [
  36. 1995,1996,1997,1998,1999,
  37. 2000,2001,2002,2003,2004,
  38. 2005,2006,2007,2008,2009,
  39. 2010,2011,2012,2013,2014
  40. ],
  41. default: 2008
  42. },
  43. safety: {
  44. type: "integer",
  45. format: "rating",
  46. maximum: "5",
  47. exclusiveMaximum: false,
  48. readonly: false
  49. }
  50. }
  51. }
  52. });
  53. // Hook up the submit button to log to the console
  54. document.getElementById('submit').addEventListener('click',function() {
  55. // Get the value from the editor
  56. console.log(editor.getValue());
  57. });
  58. </script>
  59. </body>
  60. </html>