formio.js icon indicating copy to clipboard operation
formio.js copied to clipboard

[BUG] When adding a Select Boxes with a few values, the defaultValue property always has an invalid value.

Open pboucher1960 opened this issue 1 year ago • 4 comments

Describe the bug When adding a Select Boxes to a form with a few values, the defaultValue property field always has an invalid value until we select and unselect one of the existing values as a default value.

Version/Branch The latest version of the Form.io playground

To Reproduce Steps to reproduce the behavior:

  1. In the Form.io playground, create a form.
  2. Add a "Select Boxes" component.
  3. In the "Data" tab, set the "Data Source Type" property to "Values".
  4. Add a few values (Option1, Option2 and Option3 for this example).
  5. Save the component and look at the generated JSON schema.
{
    "display": "form",
    "components": [
        {
            "label": "Select Boxes",
            "optionsLabelPosition": "right",
            "tableView": false,
            "values": [
                {
                    "label": "Option1",
                    "value": "option1",
                    "shortcut": ""
                },
                {
                    "label": "Option2",
                    "value": "option2",
                    "shortcut": ""
                },
                {
                    "label": "Option3",
                    "value": "option3",
                    "shortcut": ""
                }
            ],
            "validateWhenHidden": false,
            "key": "selectBoxes",
            "type": "selectboxes",
            "input": true,
            "inputType": "checkbox",
            "defaultValue": {
                "o": false
            }
        }
    ]
}
  1. Edit the component.
  2. In the "Data" tab, check and uncheck one of the values under the "Default Value" property.
  3. Save the component and look at the generated JSON schema.
{
    "display": "form",
    "components": [
        {
            "label": "Select Boxes",
            "optionsLabelPosition": "right",
            "tableView": false,
            "defaultValue": {
                "option1": false,
                "option2": false,
                "option3": false
            },
            "values": [
                {
                    "label": "Option1",
                    "value": "option1",
                    "shortcut": ""
                },
                {
                    "label": "Option2",
                    "value": "option2",
                    "shortcut": ""
                },
                {
                    "label": "Option3",
                    "value": "option3",
                    "shortcut": ""
                }
            ],
            "validateWhenHidden": false,
            "key": "selectBoxes",
            "type": "selectboxes",
            "input": true,
            "inputType": "checkbox"
        }
    ]
}

Expected behavior I would expect the have the same JSON Schema as in the result of step 9.

pboucher1960 avatar Nov 05 '24 21:11 pboucher1960

I'm trying to understand notion of "the defaultValue property always has an invalid value".

When you look at the submission json you can see they are being set to "false" as expected.

lane-formio avatar Nov 07 '24 16:11 lane-formio

@lane-formio When you look at the json under step 5, the default value is "o": false. The "o" option is not a valid value since, in my example, the only possible values are "option1", "option2" and "option3".

pboucher1960 avatar Nov 07 '24 16:11 pboucher1960

Ah, I see, I missed that. I'll get this reviewed more in-depth.

lane-formio avatar Nov 07 '24 16:11 lane-formio

We created a ticket for this which is being worked on for new versions of the renderer. Ticket for internal tracking: FIO-9327

daneformio avatar Nov 13 '24 14:11 daneformio