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

Array-elements are deactivated within selectfieldsets #5

Closed Gitward closed 9 years ago

Gitward commented 9 years ago

I added the following JSON Form object to http://ulion.github.io/jsonform/playground/

{
        schema: {
          name: {
            type: 'string',
            title: 'Name',
            required: true
          },
          age: {
            type: 'number',
            title: 'Age'
          },
          personality: {
            "type": "string",
            "title": "personality",
            "enum": ["active", "lazy"],
            "required": true,
            "default": "active"
          },
          hobbies: {
            type: 'array',
            "minItems": 2,
            "items": {
              "type": "object",
              "properties": {
                name: {
                  "type": "string",
                  "title": "Hobby",
                  "default": "Soccer"
                },
                since: {
                  "type": "string",
                  "title": "Active since",
                  "default": "2000"
                }
              }
            }
          }
        },
        "form": [
          "name",
          "age",
          {
            "type": "selectfieldset",
            "key": "personality",
            "title": "Personality",
            "items": [
              {
                "type": "fieldset",
                "htmlClass": "some-html-class",
                "title": "Your hobbies",
                "legend": "Enter your hobbies",
                "items": ["hobbies"]
              },
              {type: "fieldset", "legend": "Lazy people don't have hobbies"},
            ]
          }
        ],
        onSubmit: function (errors, values) {
          if (errors) {
            $('#res').html('<p>I beg your pardon?</p>');
          }
          else {
            $('#res').html('<p>Hello ' + values.name + '.' +
              (values.age ? '<br/>You are ' + values.age + '.' : '') +
              '</p>');
          }
        }
      }

Unfortunately, all array-elements but the first are deactivated:

ulion_1

Newly added elements are active after adding them:

ulion_2

But when changing personality from active to lazy and back to active, all array-elements but the first are deactivated:

ulion_3 ulion_4

This problem was already present from the commit 196486e The 'selectfieldset' field type may now be linked to a schema key. on

ulion commented 9 years ago

thank you, will check the reason, though not so soon. and if you can figure out how to fix it, please tell me or send a PR.

2015-03-12 0:51 GMT+08:00 Gitward notifications@github.com:

I added the following JSON Form Object to http://ulion.github.io/jsonform/playground/

{ schema: { name: { type: 'string', title: 'Name', required: true }, age: { type: 'number', title: 'Age' }, personality: { "type": "string", "title": "personality", "enum": ["active", "lazy"], "required": true, "default": "active" }, hobbies: { type: 'array', "minItems": 2, "items": { "type": "object", "properties": { name: { "type": "string", "title": "Hobby", "default": "Soccer" }, since: { "type": "string", "title": "Active since", "default": "2000" } } } } }, "form": [ "name", "age", { "type": "selectfieldset", "key": "personality", "title": "Personality", "items": [ { "type": "fieldset", "htmlClass": "some-html-class", "title": "Your hobbies", "legend": "Enter your hobbies", "items": ["hobbies"] }, {type: "fieldset", "legend": "Lazy people don't have hobbies"}, ] } ], onSubmit: function (errors, values) { if (errors) { $('#res').html('

I beg your pardon?

'); } else { $('#res').html('

Hello ' + values.name + '.' + (values.age ? '
You are ' + values.age + '.' : '') + '

'); } } }

Unfortunately, all array-elements but the first are deactivated:

[image: ulion_1] https://cloud.githubusercontent.com/assets/8510849/6601589/d65044b6-c816-11e4-999a-3c52602e6542.png

Newly added elements are active after adding them:

[image: ulion_2] https://cloud.githubusercontent.com/assets/8510849/6601617/f07a2f14-c816-11e4-891d-72e225126dbb.png

But when changing personality from active to lazy and back to active, all array-elements but the first are deactivated:

[image: ulion_3] https://cloud.githubusercontent.com/assets/8510849/6601648/228fdce2-c817-11e4-9b47-4a5ec1878e24.png [image: ulion_4] https://cloud.githubusercontent.com/assets/8510849/6601649/229c09ae-c817-11e4-9454-4326cd6bfd91.png

This problem was already present from the commit 196486e https://github.com/ulion/jsonform/commit/196486eee26959c25a36c5bf3b959e2a53d7c9e4 The 'selectfieldset' field type may now be linked to a schema key. on

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

Ulion

ulion commented 9 years ago

Fixed, please confirm. you can test either on the playground: http://ulion.github.io/jsonform/playground/ http://ulion.github.io/jsonform/playground/bootstrap3/

Gitward commented 9 years ago

Now the array-elements are not deactivated anymore. Thanks.