Skip to content

⚙️ Feature request: Clear field when hidden by condition #33

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

Open
justjam2013 opened this issue May 26, 2025 · 1 comment
Open

⚙️ Feature request: Clear field when hidden by condition #33

justjam2013 opened this issue May 26, 2025 · 1 comment

Comments

@justjam2013
Copy link

justjam2013 commented May 26, 2025

Describe the requested feature:

When creating a schema, you can use the condition property to show or hide a field based on the value of another field.

For example, in this playground example I am entering info about iPads and iPads may or may not have cellular capability.
The schema has a required checkbox field named hasCellular and a non-required textbox field named phoneNumber, which is displayed only if this iPad has cellular capabilities:

    ...
    "hasCellular": {
        "title": "iPad Has Cellular Capabilities",
        "type": "boolean",
        "required": true
    },
    "phoneNumber": {
        "title": "Phone Number",
        "type": "string",
        "required": false,
        "condition": {
            "functionBody": "return model.devices[arrayIndices].hasCellular === true;"
        }
    },
    ...

In the generated UI, I go ahead and configure an iPad that has cellular service:

  • I tick the hasCellular checkbox, and the phoneNumber field is displayed.
  • I enter the value 0123456789 in the phoneNumber textbox.

Then I realize my mistake: this iPad does not have cellular capability! So I uncheck hasCellular and the the field phoneNumber is hidden. When I click the Submit button, the json returned contains the phoneNumber field.

{
  "hasCellular": false,
  "phoneNumber": "0123456789"
}

What would I like to happen:

While the returned json is valid per the schema, it makes no sense.
My expectation would be that if the field phoneNumber is not displayed based on the condition property, then there be no entry for it in the submitted json.
Note: This behavior would not apply to a field that is marked as hidden in the schema, not displayed because the section it is in is collapsed (not expanded), or any other reason not related to condition.

I would like one of the following:

  • When the condition property returns false, the field or object is set back to being undefined
  • I can specify that when the condition property returns false, that the field or object is set back to being undefined

Maybe by changing the schema to something like this:

    ...
    "hasCellular": {
        "title": "iPad Has Cellular Capabilities",
        "type": "boolean",
        "required": true
    },
    "phoneNumber": {
        "title": "Phone Number",
        "type": "string",
        "required": false,
        "condition": {
            "functionBody": "return model.devices[arrayIndices].hasCellular === true;"
            "unsetOnFalse": true;
        }
    },
    ...

So when I uncheck the hasCellular checkbox, the submitted json looks like this:

{
  "hasCellular": false
}
@justjam2013
Copy link
Author

justjam2013 commented May 26, 2025

I just realized that it could create issues with required and default:

Field is required. This would make no sense because to enter a value the user is required to check the checkbox. So the checkbox is no longer a yes/no option. It would be a forced "yes".

Field has default. When the field is hidden the value is reset to the default value. This effectively resets the field or object back to its original state when the form was displayed.


Update: If bug #38 is fixed, then the issue with default is no longer relevant, as the default value is not returned in the form json.

@justjam2013 justjam2013 changed the title Feature request: Clear field when hidden by condition ⚙️ Feature request: Clear field when hidden by condition May 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant