usage article in README.md added
# JSON Schema form generator RenderJS gadget | # JSON Schema form generator RenderJS gadget | ||
## Usage | |||
It's assumed that a developer is familiar with RenderJS gadget documentation (https://renderjs.nexedi.com/). | |||
Gadget api is similar to any renderjs field api. | |||
```javascript | |||
gadget.render({ | |||
key: 'field_identificator', | |||
value: [1,2], | |||
schema: { | |||
type: 'array', | |||
items: { | |||
type: 'integer' | |||
} | |||
} | |||
}) | |||
``` | |||
![rendered](doc/array_rendered.png) | |||
If schema_url is specified instead of schema property then schema_url is used for schema download. | |||
Schema_url parameter should be specified for proper computation of an absolute url. If schema_url is omitted | |||
then the current gadget url is used as base_url. | |||
Parent gadget should have declared notification methods to catch validation status. | |||
```javascript | |||
rJS(window) | |||
.allowPublicAcquisition("notifyValid", function (arr, scope) { | |||
}) | |||
.allowPublicAcquisition("notifyInvalid", function (arr, scope) { | |||
}) | |||
.allowPublicAcquisition("notifyChange", function (arr, scope) { | |||
}); | |||
``` | |||
In parent gadget downloadJSON() can be declared. DownloadJSON() can be used to | |||
fetch schema from jio storage. Example: | |||
```javascript | |||
rJS(window) | |||
.allowPublicAcquisition("downloadJSON", function (arr) { | |||
var g = this, | |||
url = arr[0], | |||
reference, | |||
args; | |||
// return g.jio_getAttachment(id, "data", {format: "json"}); | |||
if (url.startsWith("urn:jio:reference?")) { | |||
reference = decodeURIComponent(url.replace("urn:jio:reference?", "")); | |||
args = { | |||
query: '(portal_type: "JSON Schema") AND ((reference: "' + reference + '"))', | |||
|
|||
limit: [0, 1], | |||
select_list: [], | |||
sort_on: [["modification_date", "descending"]] | |||
}; | |||
return g.jio_allDocs(args) | |||
.push(function (result) { | |||
return g.jio_getAttachment(result.data.rows[0].id, "data", {format: "json"}); | |||
}); | |||
} | |||
}) | |||
``` | |||
## What inside | ## What inside | ||
gadget consists of three parts: | gadget consists of three parts: | ||
... | ... |
1.03 KB