In your *config.schema.json file, If you define an element to have an "enum" property with a list of values:

...
"myField": {
  "type": "integer",
  "enum": [
    1,
    0
  ]
},
...

the json-forms library will render the resulting form control as a "select" type with "option" elements for each of the "enum" values.

In the rendered form, if you change the select's value (and then save the form), although a "change" event it emitted, it's not currently observed, and the changed to value is not saved.

The form control event listener code in "spalp-json-form-builder.js":

$(jsonFormId).on('change', 'input', event_data, function (event) {
  updateJsonFormElementData(event.data);
});

is only listening to "change" events in "inputs". If you update this to also listed to "select" controls, by adjusting the selector:

$(jsonFormId).on('change', 'input, select', event_data, function (event) {
  updateJsonFormElementData(event.data);
});

the value is then correctly saved when the form save is done.

A further issue though, related to this, is that when you reload the form, json-forms library renders the generated select with the first "option" element selected, which is possibly not the value stored in the underlying data. So it looks like some further work needs to be done, after the generated form has been rendered, to ensure that any "select" control values match the underlying data.

Comments

alex_sansom created an issue. See original summary.

alex_sansom’s picture

Issue summary: View changes
alex_sansom’s picture

I've created a pull request that should address the issue(s) mentioned above:

https://github.com/Capgemini/spalp/pull/48

alex_sansom’s picture

Status: Active » Needs review

  • malcomio committed 04d1263 on 8.x-1.x authored by alex_sansom
    Issue #3043449 by alex_sansom: Only "input" controls generated from...
alex_sansom’s picture

Status: Needs review » Fixed

This made it into Beta 9 version of the module.

https://www.drupal.org/project/spalp/releases/8.x-1.0-beta9

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.