Closed epitomus closed 9 years ago
Not an issue, you can add extra information in the items. For reference, the following json does what I want:
{
"schema": {
"choice": {
"type": "string",
"enum": [ "text", "cat" ]
},
"text": {
"type": "string",
"title": "Text"
},
"category": {
"type": "string",
"title": "Category",
"enum": [
"Geography",
"Entertainment",
"History",
"Arts",
"Science",
"Sports"
]
}
},
"form": [
{
"type": "selectfieldset",
"key": "choice",
"title": "Make a choice",
"titleMap": {
"text": "Search by text",
"cat": "Search by category"
},
"items": [
{
"key": "text",
"append": "today"
},
{
"key": "category"
}
]
},
{
"type": "submit",
"value": "Submit"
}
]
}
Hmm, either there is am actual problem here or I'm missing something obvious. Hope it's the second option...
Using object types to represent sub-fields. There's 2 options, put the definition under "items" and specify the key in dot-notation which means the sub-fields don't get their form definitions:
"form": [
{
"items": [
{
"key": "text",
},
{
"key": "text.text1",
"append": "today"
},
{
"key": "text.text2",
"append": "tomorrow"
},
{
"key": "category"
}
]
}
]
Or nest the sub-fields under the items, which means the fields get their definitions, but are shown twice as the parent is listed in the items too.
"form": [
{
"type": "selectfieldset",
"key": "choice",
"title": "Make a choice",
"titleMap": {
"text": "Search by text",
"cat": "Search by category"
},
"items": [
{
"key": "text",
"items": [
{
"key": "text.text1",
"append": "today"
},
{
"key": "text.text2",
"append": "tomorrow"
},
]
},
{
"key": "category"
}
]
},
{
"type": "submit",
"value": "Submit"
}
]
Complete examples. Reference fields in dot-notation under in the form items:
{
"schema": {
"choice": {
"type": "string",
"enum": [ "text", "cat" ]
},
"text": {
"type": "object",
"properties": {
"text1": {
"type": "string",
"title": "Text1"
},
"text2": {
"type": "string",
"title": "Text2"
}
}
},
"category": {
"type": "string",
"title": "Category",
"enum": [
"Geography",
"Entertainment",
"History",
"Arts",
"Science",
"Sports"
]
}
},
"form": [
{
"type": "selectfieldset",
"key": "choice",
"title": "Make a choice",
"titleMap": {
"text": "Search by text",
"cat": "Search by category"
},
"items": [
{
"key": "text",
},
{
"key": "text.text1",
"append": "today"
},
{
"key": "text.text2",
"append": "tomorrow"
},
{
"key": "category"
}
]
},
{
"type": "submit",
"value": "Submit"
}
]
}
Nest sub-fields in an item:[]
{
"schema": {
"choice": {
"type": "string",
"enum": [ "text", "cat" ]
},
"text": {
"type": "object",
"properties": {
"text1": {
"type": "string",
"title": "Text1"
},
"text2": {
"type": "string",
"title": "Text2"
}
}
},
"category": {
"type": "string",
"title": "Category",
"enum": [
"Geography",
"Entertainment",
"History",
"Arts",
"Science",
"Sports"
]
}
},
"form": [
{
"type": "selectfieldset",
"key": "choice",
"title": "Make a choice",
"titleMap": {
"text": "Search by text",
"cat": "Search by category"
},
"items": [
{
"key": "text",
"items": [
{
"key": "text.text1",
"append": "today"
},
{
"key": "text.text2",
"append": "tomorrow"
},
]
},
{
"key": "category"
}
]
},
{
"type": "submit",
"value": "Submit"
}
]
}
To custom sub items, you only need help of "customFormItems" with "text.text1" and "text.text2" as keys with their form definitions.
2015-08-17 12:24 GMT+08:00 epitomus notifications@github.com:
Hmm, either there is am actual problem here or I'm missing something obvious. Hope it's the second option...
Using object types to represent sub-fields. There's 2 options, put the definition under "items" and specify the key in dot-notation which means the sub-fields don't get their form definitions:
"form": [ { "items": [ { "key": "text", }, { "key": "text.text1", "append": "today" }, { "key": "text.text2", "append": "tomorrow" }, { "key": "category" } ] } ]
Or nest the sub-fields under the items, which means the fields get their definitions, but are shown twice as the parent is listed in the items too.
"form": [ { "type": "selectfieldset", "key": "choice", "title": "Make a choice", "titleMap": { "text": "Search by text", "cat": "Search by category" }, "items": [ { "key": "text", "items": [ { "key": "text.text1", "append": "today" }, { "key": "text.text2", "append": "tomorrow" }, ] }, { "key": "category" } ] }, { "type": "submit", "value": "Submit" } ]
Complete examples. Reference fields in dot-notation under in the form items:
{ "schema": { "choice": { "type": "string", "enum": [ "text", "cat" ] }, "text": { "type": "object", "properties": { "text1": { "type": "string", "title": "Text1" }, "text2": { "type": "string", "title": "Text2" } } }, "category": { "type": "string", "title": "Category", "enum": [ "Geography", "Entertainment", "History", "Arts", "Science", "Sports" ] } }, "form": [ { "type": "selectfieldset", "key": "choice", "title": "Make a choice", "titleMap": { "text": "Search by text", "cat": "Search by category" }, "items": [ { "key": "text", }, { "key": "text.text1", "append": "today" }, { "key": "text.text2", "append": "tomorrow" }, { "key": "category" } ] }, { "type": "submit", "value": "Submit" } ] }
Nest sub-fields in an item:[]
{ "schema": { "choice": { "type": "string", "enum": [ "text", "cat" ] }, "text": { "type": "object", "properties": { "text1": { "type": "string", "title": "Text1" }, "text2": { "type": "string", "title": "Text2" } } }, "category": { "type": "string", "title": "Category", "enum": [ "Geography", "Entertainment", "History", "Arts", "Science", "Sports" ] } }, "form": [ { "type": "selectfieldset", "key": "choice", "title": "Make a choice", "titleMap": { "text": "Search by text", "cat": "Search by category" }, "items": [ { "key": "text", "items": [ { "key": "text.text1", "append": "today" }, { "key": "text.text2", "append": "tomorrow" }, ] }, { "key": "category" } ] }, { "type": "submit", "value": "Submit" } ] }
— Reply to this email directly or view it on GitHub https://github.com/ulion/jsonform/issues/22#issuecomment-131675711.
Ulion
I've never seen that before, but it works perfectly! I had to look through the jsonform.js file to figure out how it works as I couldn't find any documentation for it.
For the curious, the way you use it is as follows (implementing the example above):
{
"schema": {
"choice": {
"type": "string",
"enum": [ "text", "cat" ]
},
"text": {
"type": "object",
"properties": {
"text1": {
"type": "string",
"title": "Text1"
},
"text2": {
"type": "string",
"title": "Text2"
}
}
},
"category": {
"type": "string",
"title": "Category",
"enum": [
"Geography",
"Entertainment",
"History",
"Arts",
"Science",
"Sports"
]
}
},
"form": [
{
"type": "selectfieldset",
"key": "choice",
"title": "Make a choice",
"titleMap": {
"text": "Search by text",
"cat": "Search by category"
},
"items": [
{
"key": "text",
},
{
"key": "category"
}
],
},
{
"type": "submit",
"value": "Submit"
}
],
"customFormItems": {
"text.text1": {
"append": "today"
},
"text.text2": {
"append": "tomorrow"
}
}
}
yes, it's not documented, only in my dev branch here, but also in some of my version of playground examples: e.g. http://ulion.github.io/jsonform/playground/bootstrap3/?example=fields-checkboxes
2015-08-17 13:20 GMT+08:00 epitomus notifications@github.com:
I've never seen that before, but it works perfectly! I had to look through the jsonform.js file to figure out how it works as I couldn't find any documentation for it.
For the curious, the way you use it is as follows (implementing the example above):
{ "schema": { "choice": { "type": "string", "enum": [ "text", "cat" ] }, "text": { "type": "object", "properties": { "text1": { "type": "string", "title": "Text1" }, "text2": { "type": "string", "title": "Text2" } } }, "category": { "type": "string", "title": "Category", "enum": [ "Geography", "Entertainment", "History", "Arts", "Science", "Sports" ] } }, "form": [ { "type": "selectfieldset", "key": "choice", "title": "Make a choice", "titleMap": { "text": "Search by text", "cat": "Search by category" }, "items": [ { "key": "text", }, { "key": "category" } ], }, { "type": "submit", "value": "Submit" } ], "customFormItems": { "text.text1": { "append": "today" }, "text.text2": { "append": "tomorrow" } } }
— Reply to this email directly or view it on GitHub https://github.com/ulion/jsonform/issues/22#issuecomment-131680946.
Ulion
Really useful! Are there any other top-level directives like form and value?
Hmm, "disabled": true
doesn't seem to work in customFormItems
. All the other directives I've tried do...
probably no. if there is, it will in the playground examples.
2015-08-17 13:35 GMT+08:00 epitomus notifications@github.com:
Really useful! Are there any other top-level directives like form and value?
— Reply to this email directly or view it on GitHub https://github.com/ulion/jsonform/issues/22#issuecomment-131684315.
Ulion
then it's not related to customFormItems, must be the specific use case of yours.
please make an issue with full info.
2015-08-17 13:40 GMT+08:00 epitomus notifications@github.com:
Hmm, "disabled": true doesn't seem to work in customFormItems. All the other directives I've tried do...
— Reply to this email directly or view it on GitHub https://github.com/ulion/jsonform/issues/22#issuecomment-131685650.
Ulion
If you create a customfieldset, you cannot have the fields present in the form section as they are created dynamically. If you do, it causes name clashes, and will also show the field all the time.