-
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
Make fields with const
pre-fiiled and readonly
#3843
base: main
Are you sure you want to change the base?
Conversation
@@ -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; |
There was a problem hiding this comment.
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
?
* 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 <abdallah.al-soqatri@aspentech.com> Co-authored-by: Heath C <51679588+heath-freenome@users.noreply.github.com>
This issue has been automatically marked as possibly close because it has not had recent activity. It will be closed if no further activity occurs. Please leave a comment if this is still an issue for you. Thank you. |
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 theconst
value and leave blank input for users.Checklist
npm run test:update
to update snapshots, if needed.