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

Make fields with const pre-fiiled and readonly #3843

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

linpc
Copy link

@linpc linpc commented Aug 26, 2023

Reasons for making this change

fixes #2600

If fields have const definition, make the value as pre-filled default and also make the fields readonly. (current logic will just ignore the const value and leave blank input for users.

image

Checklist

  • I'm updating documentation
  • I'm adding or updating code
    • I've added and/or updated tests. I've run npm run test:update to update snapshots, if needed.
    • I've updated docs if needed
    • I've updated the changelog with a description of the PR
  • I'm adding a new feature
    • I've updated the playground with an example use of the feature

@@ -177,6 +185,8 @@ export function computeDefaults<T = any, S extends StrictRJSFSchema = RJSFSchema
defaults = mergeObjects(defaults!, schema.default as GenericObjectType) as T;
} else if (DEFAULT_KEY in schema) {
defaults = schema.default as unknown as T;
} else if (CONST_KEY in schema) {
defaults = schema.const as unknown as T;
Copy link
Member

@heath-freenome heath-freenome Aug 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Const are different than defaults in that they should ALWAYS be set regardless of those values of the experimental_defaultFormStateBehavior.emptyObjectFields that restrict how defaults are set. I'm not entirely sure the best approach to updating maybeAddDefaultToObject() to understand the difference. I'm curious to see what you come up with. Maybe passing parentConsts along side of parentDefaults?

@rbavery rbavery mentioned this pull request Jul 23, 2024
4 tasks
heath-freenome added a commit that referenced this pull request Oct 21, 2024
* Make fields with const pre-fiiled and readonl

* fixed issue with default on root level.

* fixed array const populate values

* fixed array issue and written tests to cover the behavior

* updated changeLog

* fixed issue with core failing tests.

* changed changeLog to rerun tests

* improvement based on feedback

* Update packages/utils/test/schema/getDefaultFormStateTest.ts

Adding default that should not be used

* Update packages/utils/test/schema/getDefaultFormStateTest.ts

Fix linter

---------

Co-authored-by: Abdallah Al-Soqatri <[email protected]>
Co-authored-by: Heath C <[email protected]>
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

Successfully merging this pull request may close these issues.

Prefilled, readonly text field for const string types
2 participants