jquery.dform icon indicating copy to clipboard operation
jquery.dform copied to clipboard

JSON Schema integration (feature request)

Open nmorse opened this issue 16 years ago • 7 comments

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.

nmorse avatar Oct 06 '10 16:10 nmorse

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)?

daffl avatar Oct 06 '10 16:10 daffl

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.

daffl avatar Oct 19 '10 18:10 daffl

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

edanuff avatar Feb 22 '11 23:02 edanuff

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.

daffl avatar Feb 23 '11 04:02 daffl

Hi there, is this still viable? I would like to use JSON Schema objects to generate forms

kokujin avatar Aug 09 '16 05:08 kokujin

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.

daffl avatar Aug 09 '16 05:08 daffl

Nice @daffl , is the usage of converters documented somewhere? I could give it a try. Any list on what is missing from your implementation?

kokujin avatar Aug 09 '16 05:08 kokujin