brutusin / json-forms

JSON Schema to HTML form generator, supporting dynamic subschemas (on the fly resolution). Extensible and customizable library with zero dependencies. Bootstrap add-ons provided
http://brutusin.org/json-forms
Apache License 2.0
607 stars 168 forks source link

Support for optional Objects #53

Closed dnault closed 7 years ago

dnault commented 7 years ago

Currently if the schema has an object property, the form data always contains the object even if it's marked as "required": false.

It would be great if the user could opt out of setting a value for the object.

Possible solution would be for optional objects to have an "Add Item" button similar to the one for arrays (but of course limited to one item).

For example here's a form schema with an optional "widget" object. Desired behavior is that if the user does not specify a widget, the data is {} instead of {"widget":{}}.

{
  "$schema": "http://json-schema.org/draft-03/schema#",
  "type": "object",
  "properties": {
    "widget": {
      "type": "object",
      "id": "urn:jsonschema:com:example:Widget",
      "required": false,
      "properties": {
        "name": {
          "type": "string"
        }
      }
    }
  }
}
dnault commented 7 years ago

Thanks for addressing optional booleans! I don't know if objects are as straightforward, but I hope it doesn't hurt to ask :)

idelvall commented 7 years ago

Fixing version v1.5.2