-
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
Consider reverting "Make fields with const pre-fiiled and readonly" #4344
Comments
@MarekBodingerBA According to the spec a const value for a field restricts that field to have one value (i.e. it can never be changed). Is the idea that const for optional fields should not prefill? Also, you could use the |
If you can prefill your form data and configure your uiSchema, you could do something like this to get the behavior you're looking for. But if that's not an option for you, we might need to look into new feature flags. |
Ah wait, we also made the field readonly if const was specified. Perhaps that is what you are asking to roll-back? |
@heath-freenome While I understand the spec's requirements, there might be legitimate use cases, such as an "I Agree" checkbox that should ultimately be checked true but not initially. How would you handle such a case? Regarding "readonly": What's the standard for this library? Are other data types automatically set to readonly based on the schema, or is this the only case? If it's the only case, it should be considered whether this behavior is wanted for others or if there are other instances and it's consistent with the library's expected behavior. @nickgros We unfortunately cannot prefill our form data due to the highly dynamic nature of our forms. We actually use I think there are three options:
What are your thoughts? Thanks for all your work on this. |
@MarekBodingerBA Here's what we are proposing to do:
Thoughts? |
@heath-freenome Perfect! Would it make sense to support |
That would break the spec since |
…ression Fixes rjsf-team#4344, rjsf-team#4361 and rjsf-team#4377 - In `@rjsf/utils`: - Updated the `Experimental_DefaultFormStateBehavior` type to add new optional `constAsDefaults` prop with three choices - Updated `getDefaultFormState()` to respond to the new `constAsDefaults` feature to limit `const` as defaults based on the `never` or `skipOneOf` choices - Added tests for `getDefaultFormState()` to verify the new feature - In `@rjsf/core`: - Updated `SchemaField` to remove making the field readonly when const - In `playground`: - Updated `Header` to add support for `constAsDefaults` - Updated the `CHANGELOG.md` accordingly
…ression (#4381) Fixes #4344, #4361 and #4377 - In `@rjsf/utils`: - Updated the `Experimental_DefaultFormStateBehavior` type to add new optional `constAsDefaults` prop with three choices - Updated `getDefaultFormState()` to respond to the new `constAsDefaults` feature to limit `const` as defaults based on the `never` or `skipOneOf` choices - Added tests for `getDefaultFormState()` to verify the new feature - In `@rjsf/core`: - Updated `SchemaField` to remove making the field readonly when const - In `playground`: - Updated `Header` to add support for `constAsDefaults` - Updated the `CHANGELOG.md` accordingly
Prerequisites
What theme are you using?
core
Version
5.22.0
Current Behavior
The recent implementation of prefilled, readonly fields for const values, introduced by #4326, has led to a regression impacting various use cases.
In my opinion, this change is a regression as it alters expected behaviors in forms where user interaction is required. There are legitimate scenarios where fields with const values should not be readonly, such as (see playground):
Attempting to override the prefilled value with
default
does not work as expected, further complicating form configuration. The implementation should not automatically control whether a field is readonly. Flexibility should be provided to developers to define this behavior based on the specific use case.Expected Behavior
Developers should have the option to configure whether a const field is prefilled and readonly or requires user input.
Steps To Reproduce
Environment
No response
Anything else?
No response
The text was updated successfully, but these errors were encountered: