jsonform / jsonform

Build forms from JSON Schema. Easily template-able. Compatible with Bootstrap 3 out of the box.
https://jsonform.github.io/jsonform/playground/index.html
MIT License
2.72k stars 553 forks source link

activeClass isn't applied correctly for schemas with defaults #432

Closed radiomime closed 1 year ago

radiomime commented 1 year ago

intent

I'd like to apply a bootstrap activeClass to a radiobutton with a default set.

bug

{
  "schema": {
    "language": {
      "type": "string",
      "title": "Best language",
      "enum": ["JavaScript", "Python", "PHP", "Java", "C++", "other"],
      "default": "Python"
    }
  },
  "form": [
    {
      "key": "language",
      "type": "radiobuttons",
      "activeClass": "btn-primary"
    }
  ]
}

On load, yields:

Screen Shot 2023-04-12 at 1 52 22 PM

And when a different selection (C++) is chosen, yields:

Screen Shot 2023-04-12 at 1 52 29 PM

observations

This isn't an issue when there isn't a default value set. Removing "default": "Python" in the schema section above will allow the btn-primary class to apply. But when a default is provided (with the default keyword or in a value section), the btn-success class is applied.

tchapi commented 1 year ago

Hi and thanks for the report

It should be fixed in https://github.com/jsonform/jsonform/commit/961c590237b48c13bacd533206222e043ff39c49, can you confirm?

radiomime commented 1 year ago

Thanks for the quick turn around! Confirmed, it is working for the example in the issue and in my project.