Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Boolean options are always true #442

Open
radiomime opened this issue Dec 19, 2023 · 5 comments
Open

Boolean options are always true #442

radiomime opened this issue Dec 19, 2023 · 5 comments

Comments

@radiomime
Copy link

What I want to happen

I want two radio buttons to from, and I'd like the text in the box to be different than the value being sent. I'd also like the box to be preselected if it was presubmitted (by using the value key).

Issue

No matter which button I select before submitting, the value sent is true in this example:

{
  "schema": {
    "general": {
      "type": "object",
      "properties": {
        "is_cool": {
          "title": "Are you cool?",
          "type": "boolean"
        }
      }
    }
  },
  "form": [
    {
      "type": "fieldset",
      "title": "<b>General</b>",
      "items": [
        {
          "key": "general.is_cool",
          "type": "radiobuttons",
          "activeClass": "btn-success",
          "options": [
            {
              "title": "I'm not cool",
              "value": false
            },
            {
              "title": "I am, indeed, cool",
              "value": true
            }
          ]
        }
      ]
    },
    {
      "type": "submit",
      "title": "Submit"
    }
  ],
  "value": {
    "general": {
      "is_cool": true
      }
  }
}

The value sent should be false when selecting "I'm not cool" and hitting submit

What I'd expect

This exact example works as I'd expect using strings instead of booleans:

{
  "schema": {
    "general": {
      "type": "object",
      "properties": {
        "is_cool": {
          "title": "Are you cool?",
          "type": "string"
        }
      }
    }
  },
  "form": [
    {
      "type": "fieldset",
      "title": "<b>General</b>",
      "items": [
        {
          "key": "general.is_cool",
          "type": "radiobuttons",
          "activeClass": "btn-success",
          "options": [
            {
              "title": "I'm not cool",
              "value": "false"
            },
            {
              "title": "I am, indeed, cool",
              "value": "true"
            }
          ]
        }
      ]
    },
    {
      "type": "submit",
      "title": "Submit"
    }
  ],
  "value": {
    "general": {
      "is_cool": "true"
      }
  }
}
@sdetweil sdetweil added Question usage how to use jsonform labels Dec 19, 2023
@sdetweil
Copy link
Contributor

sdetweil commented Dec 19, 2023

you might try "submit": true instead of "value":true

the doc says options are for string values not boolean

@sdetweil
Copy link
Contributor

Screenshot_20231219_081615_Chrome

@radiomime
Copy link
Author

Thanks for the reply @sdetweil.

I templated the above schema (with the value key) from this part of the projects wiki which gives a similar example, but with strings instead of boolean values.

If I don't include "value": true, both submitted values false. This is also the case if I use "submit": true instead.

@sdetweil
Copy link
Contributor

ok, I'll look at it. the doc says "strings"

@sdetweil
Copy link
Contributor

sdetweil commented Jan 9, 2024

at this time, this is currently a restriction, only works with string entities..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants