-
Notifications
You must be signed in to change notification settings - Fork 556
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
JSON Array - Unable to remove all items #33
Comments
Hi @bretrouse, Thanks for the report. If you replace For arrays, JSON Form always displays at least one item in the form. Upon submission, it takes for granted that a field left empty should be discarded from the result. To determine whether a field should be considered empty, JSON Form looks at the field's type, e.g. a The problem with {
"parameters": [
{
"value": ""
}
]
} ... which is invalid per the schema. The code could perhaps assume that it can strip anything that looks like an empty value from the resulting object, i.e. |
Either that or allow the user to explicitly remove the empty entry prior to On Thu, Dec 27, 2012 at 4:15 AM, François Daoust
|
I'm seeing the same issues with the following schema: {
"id": "VALUE_ARRAYS",
"type": "object",
"additionalProperties": false,
"properties": {
"VALUE_ARRAYS": {
"type": "array",
"required": true,
"items": {
"type": "object",
"additionalProperties": false,
"properties": {
"namespace": {
"type": "string",
"required": true,
"enum": [
"SCOPE_ONE",
"SCOPE_TWO",
"SCOPE_THREE"
]
},
"values": {
"type": "object",
"properties": {
"VALUE_ARRAY_ONE": {
"type": "array",
"required": false,
"items": {
"type": "object",
"additionalProperties": false,
"properties": {
"value": {
"type": "integer",
"required": true
},
"start": {
"type": "integer",
"required": false
},
"end": {
"type": "integer",
"required": false
},
"countsForCRC": {
"type": "boolean",
"required": false,
"default": true
}
}
}
},
"VALUE_ARRAY_TWO": {
"type": "array",
"required": false,
"items": {
"type": "object",
"additionalProperties": false,
"properties": {
"value": {
"type": "integer",
"required": true
},
"start": {
"type": "integer",
"required": false
},
"end": {
"type": "integer",
"required": false
},
"countsForCRC": {
"type": "boolean",
"required": false,
"default": true
}
}
}
}
}
}
}
}
}
}
} |
I have the same issue as @bretrouse. I think we need to allow a user to delete all the array objects (and I'm not sure why it's forced to be one?) or at least have that as an option passed to JSONForm. There are many cases where this will always break, such as whenever the array object uses an enum. This means the "empty" first object always be considered as filled in by the end user as there's no way to "deselect" the enum. Other than this slight issue I've hit, JSONForm is a wonderful library. I hope it can be resolved, especially as it seems this was placed in there as a preference rather than for a specific reason. I'll be looking into removing this limitation in my own JSONForm version. |
There was no way to suppress the last item of an array. That restriction was more for visual reasons (it usually does not look great to only see "+/-" buttons) than for deep technical reasons. In practice, not being able to remove all items creates artefact, especially if one of the fields is rendered as a select box: there is no way for JSONForm to tell whether the user actually selected something in the select box or did not want to submit anything. JSONForm always included the selected choice in the select box in the submitted object, meaning there was no proper way to reset an array. JSONForm now allows used to remove the last item in an array. Note that, when an array is first rendered, it is still rendered with one empty element as that's supposedly clearer than to display only the "+/-" buttons. We may add an option later on to override that setting and start with no array items if needed.
I just committed a fix for that issue. Users may now remove all items in an array (or a tabarray). @bretrouse I haven't checked your later schema, let me know if the fix is not enough. Note that JSONForm still renders arrays with at least one item to start with as that feels more natural than displaying only +/- buttons. |
JSONForm renders an item for arrays the first time they are rendered as it is usually better from a user experience perspective. However, if the form has already been submitted and if previous values do not contain any item for a given array, the array must be rendered without items. JSONForm still rendered an item in that case.
As an exception to the rule, JSONForm now does not render an array with an item if the JSONForm structure received contains a |
Given the following schema:
Result: The subsequent form is unable to save a parameters array with 0 items. It always displays a minimum of one item who's name is required preventing the form from being saved.
Expected: user should be able to remove all items from an array with minItems set to 0, or with no minItems set. This would save out an array [] when creating the JSON.
The text was updated successfully, but these errors were encountered: