ulion / jsonform

Build forms from JSON Schema. Easily template-able. Compatible with Twitter Bootstrap out of the box.
http://ulion.github.io/jsonform/playground/
MIT License
49 stars 27 forks source link

Failed to render array if it has more than one child #11

Closed besthyman closed 9 years ago

besthyman commented 9 years ago

I download branch "bootstrap3" and use the following codes to show a form:

var jsonfrom = $('#jsonForm').jsonForm({ schema: {"items": {"items": {"properties": {"bearer": {"required": true, "title": "Bearer", "type": "string"}, "slug": {"required": true, "title": "Slug", "type": "string"}}, "title": "Item", "type": "object"}, "type": "array"}} , form: [{"items": {"items": ["items[].slug", "items[].bearer"], "type": "section"}, "title": "Bearer tokens", "type": "array"}, {"title": "Save", "type": "submit"}], value: {"items": [{"bearer": "b1", "slug": "s1"}, {"bearer": "b2", "slug": "s2"}]}, onSubmit: function (errors, values) { alert(values); } });

There are two children in my value, {"bearer": "b1", "slug": "s1"} and {"bearer": "b2", "slug": "s2"}. Only the first one is rendered.

ulion commented 9 years ago

a simple test indicate change the form element to add "key" value to "items" for the array seems resolved the problem:

{
schema: {"items": {"items": {"properties": {"bearer": {"required": true,
"title": "Bearer", "type": "string"}, "slug": {"required": true, "title":
"Slug", "type": "string"}}, "title": "Item", "type": "object"}, "type":
"array"}}
,
form: [{"items": {"items": ["items[].slug", "items[].bearer"], "type":
"section"}, "title": "Bearer tokens", "type": "array", "key": "items"},
{"title": "Save", "type": "submit"}],
value: {"items": [{"bearer": "b1",  "slug": "s1"}, {"bearer": "b2", "slug":
"s2"}]},
onSubmit: function (errors, values) {
alert(values);
}
}

2015-05-08 10:28 GMT+08:00 besthyman notifications@github.com:

I download branch "bootstrap3" and use the following codes to show a form:

var jsonfrom = $('#jsonForm').jsonForm({ schema: {"items": {"items": {"properties": {"bearer": {"required": true, "title": "Bearer", "type": "string"}, "slug": {"required": true, "title": "Slug", "type": "string"}}, "title": "Item", "type": "object"}, "type": "array"}} , form: [{"items": {"items": ["items[].slug", "items[].bearer"], "type": "section"}, "title": "Bearer tokens", "type": "array"}, {"title": "Save", "type": "submit"}], value: {"items": [{"bearer": "b1", "slug": "s1"}, {"bearer": "b2", "slug": "s2"}]}, onSubmit: function (errors, values) { alert(values); } });

There are two children in my value, {"bearer": "b1", "slug": "s1"} and {"bearer": "b2", "slug": "s2"}. Only the first one is rendered.

— Reply to this email directly or view it on GitHub https://github.com/ulion/jsonform/issues/11.

Ulion