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
3 changes: 3 additions & 0 deletions app/views/dynamic_forms/custom_forms/_integration.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
.col-md-6
%h3 JSON Schema
#json_editor_container.w-100.mb-5{:style => "height: 600px;"}
.col-md-6
%h3 Preview
#custom-form.w-100.mb-5{:style => "height: 600px;"}
.col-md-6
%h3 UI Schema
#json_editor_container_ui.w-100.mb-5{:style => "height: 600px;"}
35 changes: 35 additions & 0 deletions vendor/assets/javascripts/CustomForm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
"use strict";

Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;

var _react = _interopRequireDefault(require("react"));

var _reactDom = _interopRequireDefault(require("react-dom"));

var _reactJsonschemaForm = _interopRequireDefault(require("react-jsonschema-form"));

var _this = void 0;

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

var CustomForm = function CustomForm(container, jsonSchema, uiSchema) {
_react.default.createElement("div", null, _react.default.createElement(_reactJsonschemaForm.default, {
schema: { jsonSchema },
uiSchema: { uiSchema }
}));
return renderCustomForm(container, jsonSchema, uiSchema);
};

var renderCustomForm = function (container, jsonSchema, uiSchema){
_reactDom.default.render(_react.default.createElement(CustomForm, {
json_schema: jsonSchema,
ui_schema: uiSchema
}), document.getElementById(container));
}


var _default = CustomForm;
exports.default = _default;
11 changes: 11 additions & 0 deletions vendor/assets/javascripts/dynamic_forms.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import CustomForm from "./CustomForm";

//= require jsoneditor
//= require CustomForm

document.addEventListener("DOMContentLoaded", function(){
initJsonEditor();
initJsonEditorUi();
updatePreview();
});

initJsonEditor = function initJsonEditor(){
Expand Down Expand Up @@ -44,3 +48,10 @@ initJsonEditorUi = function (){
const jsonEditor = new JSONEditor(jsonEditorContainer, jsonEditorOptions);
jsonEditor.set(JSON.parse(uiSchemaField.value));
}

updatePreview = function updatePreview() {
const jsonSchemaField = document.getElementById("custom_form_json_schema");
const uiSchemaField = document.getElementById("custom_form_ui_schema");
const previewContainer = document.getElementById("custom-form");
CustomForm(previewContainer, jsonSchemaField, uiSchemaField);
}