Open Gitward opened 9 years ago
where did you tested it? tested on my playground, no problem.
2015-04-28 19:58 GMT+08:00 Gitward notifications@github.com:
This problem seems to be similar to #5 https://github.com/ulion/jsonform/issues/5
In https://github.com/ulion/jsonform/blob/dev/lib/jsonform.js#L143 it says
Input fields that are not visible are automatically disabled not to appear in the submitted form.
This works in the following form:
{ isBootstrap2 : true, schema: { name: { type: 'string', title: 'Name', required: true }, age: { type: 'number', title: 'Age' }, personality: { "type": "string", "title": "Personality", "enum": ["active", "lazy"], "required": true, "default": "lazy" }, hobby_text: { "type": "string", "title": "My hobby as a text", "description": "Enter a text about your hobbies", "required": true, "default": "Soccer is my favorite" } }, "form": [ "name", "age", { "type": "selectfieldset", "key": "personality", "title": "Personality", "items": [ { "type": "fieldset", "htmlClass": "some-html-class", "title": "Hobby text", "legend": "Enter text about your hobbies", "items": ["hobby_text"] }, {type: "fieldset", "legend": "Lazy people don't have hobbies"} ] }, { type: "submit", title: "submit" } ], onSubmit: function (errors, values) { $('#res').html('
Data:
'
- '
' + JSON.stringify(values, null, ' ') + ''- '
' + JSON.stringify(errors, null, ' ') + '' ); } }which sends
{ "name": "some name", "personality": "lazy" }
But when the field hobby_text is nested in another selectfieldset, the value for hobby_text is sent, even though it is hidden:
{ isBootstrap2 : true, schema: { name: { type: 'string', title: 'Name', required: true }, age: { type: 'number', title: 'Age' }, personality: { "type": "string", "title": "Personality", "enum": ["active", "lazy"], "required": true, "default": "lazy" }, hobby_text: { "type": "string", "title": "My hobby as a text", "description": "Enter a text about your hobbies", "required": true, "default": "Soccer is my favorite" } }, "form": [ "name", "age", { "type": "selectfieldset", "key": "personality", "title": "Personality", "items": [ { "type": "fieldset", "htmlClass": "some-html-class", "title": "Hobby text", "legend": "Enter text about your hobbies", "items": ["hobby_text"] }, {type: "fieldset", "legend": "Lazy people don't have hobbies"} ] }, { type: "submit", title: "submit" } ], onSubmit: function (errors, values) { $('#res').html('
Data:
'
- '
' + JSON.stringify(values, null, ' ') + ''- '
' + JSON.stringify(errors, null, ' ') + '' ); } }sends:
{ "name": "some name", "personality": "lazy", "hobby_text": "Soccer is my favorite" }
— Reply to this email directly or view it on GitHub https://github.com/ulion/jsonform/issues/10.
Ulion
I used: http://ulion.github.io/jsonform/playground/ Steps to reproduce:
{
isBootstrap2 : true,
schema: {
name: {
type: 'string',
title: 'Name',
required: true
},
age: {
type: 'number',
title: 'Age'
},
personality: {
"type": "string",
"title": "Personality",
"enum": ["active", "lazy"],
"required": true,
"default": "lazy"
},
hobby_text: {
"type": "string",
"title": "My hobby as a text",
"description": "Enter a text about your hobbies",
"required": true,
"default": ""
},
hobbies: {
type: 'array',
"minItems": 1,
"items": {
"type": "object",
"properties": {
name: {
"type": "string",
"title": "Hobby",
"default": "Soccer"
},
since: {
"type": "string",
"title": "Active since",
"default": "2000"
}
}
}
}
},
"form": [
"name",
"age",
{
"type": "selectfieldset",
"key": "personality",
"title": "Personality",
"items": [
{
"type": "selectfieldset",
"title": "Select timing mode",
"items": [
{
"type": "fieldset",
"htmlClass": "some-html-class",
"title": "Hobby text",
"legend": "Enter text about your hobbies",
"items": ["hobby_text"]
}, {
"type": "fieldset",
"htmlClass": "some-html-class",
"title": "Your hobbies",
"legend": "Enter your hobbies as a list",
"items": ["hobbies"]
}
]
},
{type: "fieldset", "legend": "Lazy people don't have hobbies"},
]
},
{
type: "submit",
title: "submit"
}
],
onSubmit: function (errors, values) {
$('#res').html('<p>Data:</p>'
+ '<pre>' + JSON.stringify(values, null, ' ') + '</pre>'
+ '<pre>' + JSON.stringify(errors, null, ' ') + '</pre>'
);
}
}
submit
(afterwards a tooltip occurs close to the input-field of name, asking you to fill out that field)There are 2 issues.
So, what you need, is make that field "required" only when Personality is "active", for that purpose, you still can not mark the hobby_text field "required". But how to achieve that, is still a problem.
This problem seems to be similar to https://github.com/ulion/jsonform/issues/5
In https://github.com/ulion/jsonform/blob/dev/lib/jsonform.js#L143 it says
This works in the following form:
which sends
But when the field
hobby_text
is nested in anotherselectfieldset
, the value forhobby_text
is sent, even though it is hidden:sends:
It becomes real strange, when you set the default-value of
hobby_text
to empty String:Then the![ulion2](https://cloud.githubusercontent.com/assets/8510849/7370102/f4871a92-edb7-11e4-8d55-cd393150ceed.png)
Please fill out this field
-message occurs in the upper-left corner of the browser window:The notification in the upper left corner does not show up in Chromium. But Chromium does also not send the data.