-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
better support for const #1241
Comments
I think the two you enumerated are the main things that would need to be changed. Some things to consider:
|
IMO, the default should be set to the const because the form would be invalid if using an incorrect default field. A readonly field makes sense to me. I think in the case of the single enum field, I would expect the form to render a dropdown with 1 element even though a const might be the same thing. In my own usage, we sometimes populate the enum dynamically and it could only have 1 element, and is semantically different than a const. I would like for our users to know that there could be more options, but just not now. |
I agree -- makes sense, feel free to implement this in a PR. |
@epicfaace please see my bigger commit as I added pre-populating based form with const value / readonly. and if / then / else from looking at the spec
one thing to bear in mind thinking about it and the if / then / else if stuff essentually if a field is not required then it can potentually be undefined or the const value, how does ajv handle this when validating? |
Hey! I was trying to review the different issues and PR but couldn't figure out if anyone is working on this at the moment. I'm happy to contribute if I can. |
Is it possible to revive this somehow? Happy to help. Using something like typebox or in general just making high use of discriminated-unions in TS will lead you to a PITA here as the current behaviour for |
@chrisui With the v5 beta just being released this is the perfect time to help. |
Hi, we have forms where we use 1. Const + hidden widgetA form with What I'd expect: Actual: The workaround for this is to use 2. Const + default + hidden widgetA form with Expected: Actual: Old value is not overriden, no way to change and the form. Form is always invalid. 3. Const with complex data + hidden widgetWe'd also want to use Expected: Actual: I hope these examples provide some context if you plan to work with this issue! Thanks for the library, awesome work! |
So one use case where const should affect the UI and currently doesn't is when you want the user to select between multiple consts: {
"oneOf": [
{
"const": "foo"
},
{
"const": "bar"
}
]
} This displays nothing at all, which is an issue because the user needs to be asked to choose between these two options. Of course in this case an enum could be used, but actually it's a better practise to use |
@multimeric I agree we need to fix this. Are you willing to provide a PR for it? If so, I could walk you through the steps of fixing this. |
Prerequisites
Description
Currently,
const
is only used to validate the form data, but there is no UX to enforce it. This is a proposal to add more support ofconst
.Steps to Reproduce
https://rjsf-team.github.io/react-jsonschema-form/#eyJmb3JtRGF0YSI6e30sInNjaGVtYSI6eyJ0aXRsZSI6IkEgcmVnaXN0cmF0aW9uIGZvcm0iLCJkZXNjcmlwdGlvbiI6IkEgc2ltcGxlIGZvcm0gZXhhbXBsZS4iLCJ0eXBlIjoib2JqZWN0IiwicHJvcGVydGllcyI6eyJmaXJzdE5hbWUiOnsidHlwZSI6InN0cmluZyIsInRpdGxlIjoiRmlyc3QgbmFtZSIsImNvbnN0IjoiQ2h1Y2sifX19LCJ1aVNjaGVtYSI6e319
Expected behavior
const
should be respected in various areas:Actual behavior
Only form validation respects
const
. It does not get applied as a default form state and there is no UI indiciation that a field cannot be changed from a certain value.Version
1.3.0
The text was updated successfully, but these errors were encountered: