JSON Schema integration (feature request)
Link to or embed a "JSON Schema". To be used for a unified source of information on the types of properties, and other qualifying meta data.
I would like to integrate a jSON Schema, but due to the extensible nature of the plugin it might be not that easy to do so. Types can have any valid HTML attribute as an option whereas each subscriber has its own set of valid options (I can imagine to supply an optional schema for every subscriber registered). Do you have an idea on what schema validator to use (best would be one that can create some documentation as well)?
Btw check out the new documentation at http://neyeon.com/p/jquery.dform/doc/files/dform-subscribers-js.html . It shows all the options available and how to add you own. I sill want to generate a JSON schema from it though.
Just played with this idea and it's really simple to transform json-schema to your format, so maybe you could do this as some sort of extension. This is what I through together in a few minutes to test the concept:
function jsonSchemaToDForm(schema, obj) {
var dform = { elements : [] };
for (var propName in schema.properties) {
var property = schema.properties[propName];
var type = property.type;
if (type == "string") {
var value = obj[propName];
if (!value) value = "";
var element = {
"name" : "ui-form-" + propName,
"id" : "ui-form-" + propName,
"caption" : property.title,
"type" : "text",
"value" : value
};
dform.elements.push(element);
dform.elements.push({
"type" : "br"
});
} else if (type == "object") {
var element = jsonSchemaToDForm(property, obj);
element.type = "fieldset";
element.caption = property.title;
dform.elements.push(element);
}
}
return dform;
}
Ideally, mapping in the json-schema validation and things like arrays and so on would be part of real support, as well as having a facility for getting the data back out of the form into json like reformed does - https://github.com/BigBlueHat/reformed
This is a good Idea. I added a namespace for $.dform.converters. When creating a form you will soon be able to pass the name of a converter (e.g. "dform" for the default forms, "json-schema" for json schema or "json" for converting JSON into a dform definition like BigBlueHats reformed does).
A converter will take the options passed to the buildForm or formElement function and return the dForm object. I would use your example as a basic JSON schema converter and then we could go over the details of the specification from there.
Hi there, is this still viable? I would like to use JSON Schema objects to generate forms
There is an old start for a JSON schema converter here: https://github.com/daffl/jquery.dform/blob/master/src/dform.converters.js#L71. It still needs some work and someone to take it on though.
Nice @daffl , is the usage of converters documented somewhere? I could give it a try. Any list on what is missing from your implementation?