read-only.html 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8"/>
  5. <script src="../../dist/jsoneditor.js"></script>
  6. </head>
  7. <body>
  8. <textarea class="debug" cols="30" rows="10"></textarea>
  9. <button class='get-value'>Get Value</button>
  10. <div class='container'></div>
  11. <script>
  12. var container = document.querySelector('.container');
  13. var debug = document.querySelector('.debug');
  14. var getValue = document.querySelector('.get-value');
  15. var schema = {
  16. "type": "object",
  17. "title": "readOnly",
  18. "properties": {
  19. "string": {
  20. "title": "string",
  21. "type": "string",
  22. "readOnly": true,
  23. "default": "some value"
  24. },
  25. "number": {
  26. "title": "number",
  27. "type": "number",
  28. "readOnly": true,
  29. "default": 5.5
  30. },
  31. "integer": {
  32. "title": "integer",
  33. "type": "integer",
  34. "readOnly": true,
  35. "default": 5
  36. },
  37. "multiselect": {
  38. "title": "multiselect",
  39. "type": "array",
  40. "format": "multiselect",
  41. "uniqueItems": true,
  42. "readOnly": true,
  43. "items": {
  44. "type": "string",
  45. "enum": ["value1","value2"]
  46. }
  47. },
  48. "select": {
  49. "title": "select",
  50. "type": "boolean",
  51. "readOnly": true
  52. },
  53. rating: {
  54. "title": "rating",
  55. "readOnly": true,
  56. "type": "integer",
  57. "format": "rating",
  58. "maximum": "5",
  59. "exclusiveMaximum": false
  60. },
  61. checkbox: {
  62. "title": "checkbox",
  63. "format": "checkbox",
  64. "type": "boolean",
  65. "readOnly": true
  66. }
  67. }
  68. };
  69. var editor = new JSONEditor(container, {
  70. schema: schema
  71. });
  72. getValue.addEventListener('click', function () {
  73. debug.value = JSON.stringify(editor.getValue());
  74. });
  75. </script>
  76. </body>
  77. </html>