Coder Social home page Coder Social logo

Comments (6)

tidoust avatar tidoust commented on May 22, 2024

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.

bretrouse avatar bretrouse commented on May 22, 2024

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.

bretrouse avatar bretrouse commented on May 22, 2024

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.

Smerity avatar Smerity commented on May 22, 2024

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.

tidoust avatar tidoust commented on May 22, 2024

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.

tidoust avatar tidoust commented on May 22, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.