Comments (6)
Hi @bretrouse,
Thanks for the report. If you replace any
with string
you should be able to submit the form (JSON Form would actually not set the parameters
property in the returned object in that case).
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 string
field is empty if the form submission returns an empty string for that field.
The problem with any
is that JSON Form cannot assume much about that field, and it cannot tell whether an empty string is an empty value in particular. It keeps the empty string as a result, leading to:
{
"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. null
, ""
, {}
, []
.
from jsonform.
Either that or allow the user to explicitly remove the empty entry prior to
saving. Is there a need to display one item in the form at all times?
On Thu, Dec 27, 2012 at 4:15 AM, François Daoust
[email protected]:
Hi @bretrouse https://github.com/bretrouse,
Thanks for the report. If you replace any with string you should be able
to submit the form (JSON Form would actually not set the parametersproperty in the returned object in that case).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 stringfield is empty if the form submission returns an empty string for that
field.The problem with any is that JSON Form cannot assume much about that
field, and it cannot tell whether an empty string is an empty value in
particular. It keeps the empty string as a result, leading to:{
"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. null, "", {}, [].—
Reply to this email directly or view it on GitHubhttps://github.com//issues/33#issuecomment-11704031.
from jsonform.
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
}
}
}
}
}
}
}
}
}
}
}
from jsonform.
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.
from jsonform.
I just committed a fix for that issue. Users may now remove all items in an array (or a tabarray).
The "remove" button becomes disabled when there are no more items to remove.
@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.
from jsonform.
As an exception to the rule, JSONForm now does not render an array with an item if the JSONForm structure received contains a value
object that represents previously submitted values and that does not have any item for that array.
from jsonform.
Related Issues (20)
- How to Map My Custom JSON Value to JSON Forms HOT 8
- titleMap in selectbox array HOT 4
- [Question] How to get the markup of the form programatically in JS without attaching it to a DOM element HOT 3
- How to make a valid json with a onChange function ? HOT 4
- Add custom field to fieldset HOT 2
- activeClass isn't applied correctly for schemas with defaults HOT 2
- How to build a stepper form HOT 4
- process change, just fyi.. all PRs against develop branch
- Expanded Fieldset + Default TabIndex set - Collapse issue (bug) HOT 4
- tabs-left not supported in bootstrap v3
- Hide submit button HOT 2
- How to escape slash in scope HOT 3
- Rendering fails if property name contains dots HOT 1
- Missing array brackets [] on array items when using a custom field type HOT 1
- Error: JSONForm does not yet support schemas that use the $ref keyword. See: #54" HOT 2
- Boolean options are always true HOT 5
- How to use this library with bundler HOT 1
- How to show error after a control value is changed, HOT 1
- date / datetime formatting HOT 3
- Advancedfieldset form folding click handle gets duplicated when jsonform gets called again causing the folded form to flick HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jsonform.