ulion / jsonform

Build forms from JSON Schema. Easily template-able. Compatible with Twitter Bootstrap out of the box.
http://ulion.github.io/jsonform/playground/
MIT License
49 stars 27 forks source link

Alternatives using selectfieldset and schema keys does not work in arrays #19

Closed epitomus closed 9 years ago

epitomus commented 9 years ago

If you create a selectfieldset under an array, it shows all alternatives when loaded. The following JSON highlights the problem, and is a modification from this example in the playground: Fields - Alternative with schema key.

There are additional problems with this example. If you add a new item to the array, it shows only one alternative. If you change from text to category, it shows the incorrect alternative, then if you change back to text it shows both alternatives.

{
  "schema": {
    "list": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "choice": {
            "type": "string",
            "enum": [ "text", "cat" ]
          },
          "text": {
            "type": "string",
            "title": "Text"
          },
          "category": {
            "type": "string",
            "title": "Category",
            "enum": [
              "Geography",
              "Entertainment",
              "History",
              "Arts",
              "Science",
              "Sports"
            ]
          }
        }
      }
    }
  },
  "form": [
    {
      "type": "tabarray",
      "key": "list",
      "items": {
        "type": "selectfieldset",
        "key": "list[].choice",
        "title": "Make a choice",
        "titleMap": {
          "text": "Search by text",
          "cat": "Search by category"
        },
        "items": [
          "list[].text",
          "list[].category"
        ]
      }
    },
    {
      "type": "submit",
      "value": "Submit"
    }
  ]
}

Examples:

image

image

image

image

ulion commented 9 years ago

it seems in the result form, node.childPos are all zero for the text and category sub nodes.

I do remember somebody else mentioned this in other issue.

2015-08-13 13:07 GMT+08:00 epitomus notifications@github.com:

If you create a selectfieldset under an array, it shows all alternatives when loaded. The following JSON highlights the problem, and is a modification from this example in the playground: Fields - Alternative with schema key http://ulion.github.io/jsonform/playground/bootstrap3/?example=fields-selectfieldset-key .

There are additional problems with this example. If you add a new item to the array, it shows only one alternative. If you change from text to category, it shows the incorrect alternative, then if you change back to text it shows both alternatives.

{ "schema": { "list": { "type": "array", "items": { "type": "object", "properties": { "choice": { "type": "string", "enum": [ "text", "cat" ] }, "text": { "type": "string", "title": "Text" }, "category": { "type": "string", "title": "Category", "enum": [ "Geography", "Entertainment", "History", "Arts", "Science", "Sports" ] } } } } }, "form": [ { "type": "tabarray", "key": "list", "items": { "type": "selectfieldset", "key": "list[].choice", "title": "Make a choice", "titleMap": { "text": "Search by text", "cat": "Search by category" }, "items": [ "list[].text", "list[].category" ] } }, { "type": "submit", "value": "Submit" } ] }

Examples:

  • On load you can see both alternatives:

[image: image] https://cloud.githubusercontent.com/assets/893900/9242929/88da0660-41cc-11e5-8653-c91f5f3c1730.png

  • Adding a new item shows only the text alternative:

[image: image] https://cloud.githubusercontent.com/assets/893900/9242932/96fa4ec6-41cc-11e5-9f56-1db14b290aa4.png

  • Changing to category also only shows the text alternative:

[image: image] https://cloud.githubusercontent.com/assets/893900/9242946/aa231bae-41cc-11e5-89a0-75bada5bccdf.png

  • Changing back to text now shows both alternatives:

[image: image] https://cloud.githubusercontent.com/assets/893900/9242947/b84267bc-41cc-11e5-8f29-bd8e6d7edbe0.png

— Reply to this email directly or view it on GitHub https://github.com/ulion/jsonform/issues/19.

Ulion

epitomus commented 9 years ago

Previously raised and fixed by @wuminorb in https://github.com/ulion/jsonform/pull/13

I'd be happy if you just merged that PR :)

ulion commented 9 years ago

thank you, merged that.

epitomus commented 9 years ago

Cheers!