brutusin / brutusin/json-forms

SchemaResolver with array of objects of dynamic

Open
#109 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
618
Forks
171
PR merge metrics
No merged PRs in 30d

Description

I had an array of objects A and each of object contains filter. Each filter options will display different kinds of forms objects dynamically.

Based on the issue https://github.com/brutusin/json-forms/issues/22, the dynamic done in the first layer of the object. But I have array of objects A that doesn't work for each display.

```
var schema = {
"properties": {
"ObjectA": {
"type": "array",
"items": {
"type": "object",
"properties": { "filter": ...., "criteria": { "dependOn": ['filter'] } }
}
}
}
}
var dynamicSchema = {
"age": { type: "Object", number: 21 },
"country": { type: "Object", name: "US" }
}

var BrutusinForms = brutusin["json-forms"];
this.bf = BrutusinForms.create(schema);
this.bf.schemaResolver = (names, data, cb) => {
data.ObjectA.map((obj, ind) => {
schemas["$.ObjectA[" + ind + "].criteria"] = dynamicSchema[obj.filter]
}
cb(schemas);
}
this.bf.render(this.$refs.manageContainer);
```

The `name` always outputs `schemas["$.demographic[#].criteria"]` no matter which filter I add.
If I add `schemas["$.demographic"]`, it works for me without the filter but the dynamic schema objects.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.