-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Feat: conditional fields #7664
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
base: main
Are you sure you want to change the base?
Feat: conditional fields #7664
Changes from 3 commits
1409cc2
c8966b3
c08f32a
41b073a
e7287be
bca3f46
f670fee
3761171
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -94,6 +94,36 @@ function getFieldValue({ field, entry, isTranslatable, locale }) { | |||||||
| return entry.getIn(['data', field.get('name')]); | ||||||||
| } | ||||||||
|
|
||||||||
| function calculateCondition({field, fields, entry, locale, isTranslatable}) { | ||||||||
| const condition = field.get('condition') | ||||||||
| if (!condition) return true; | ||||||||
|
|
||||||||
| const condFieldName = condition.get('field'); | ||||||||
| const operator = condition.get('operator') || '=='; | ||||||||
| const condValue = condition.get('value'); | ||||||||
|
|
||||||||
| const condField = fields.find(f => f.get('name') === condFieldName); | ||||||||
|
||||||||
| const condField = fields.find(f => f.get('name') === condFieldName); | |
| const condField = fields.find(f => f.get('name') === condFieldName); | |
| if (!condField) return false; |
Copilot
AI
Nov 11, 2025
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.
The comparison operators use loose equality (== and !=) instead of strict equality (=== and !==). This can lead to unexpected type coercion. For example, "0" == 0 would be true with loose equality. Consider using strict equality operators for more predictable behavior.
Copilot
AI
Nov 11, 2025
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.
The copyFromOtherLocale function doesn't check if fields meet their condition before copying values. This could result in copying values to fields that are currently hidden due to unmet conditions. Consider adding a condition check similar to the one in the validate method and the render logic.
Copilot
AI
Nov 11, 2025
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.
Missing return value. When the condition is not met, this function returns undefined implicitly. For clarity and consistency with React rendering, explicitly return null:
if (!isConditionMet) return null;| if (!isConditionMet) return | |
| if (!isConditionMet) return null; |
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -69,6 +69,14 @@ function fieldsConfig() { | |||||||||
| field: { $ref: `field_${id}` }, | ||||||||||
| fields: { $ref: `fields_${id}` }, | ||||||||||
| types: { $ref: `fields_${id}` }, | ||||||||||
| condition: { | ||||||||||
| type: 'object', | ||||||||||
| properties: { | ||||||||||
| field: { type: 'string' }, | ||||||||||
| value: { types: ['string', 'boolean'] }, | ||||||||||
|
||||||||||
| value: { types: ['string', 'boolean'] }, | |
| value: { type: ['string', 'boolean'] }, |
Copilot
AI
Nov 11, 2025
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.
The schema definition for the value property is missing the number type. According to the TypeScript definition in redux.ts and index.d.ts, the value should accept string | boolean | number. Add 'number' to the types array: type: ['string', 'boolean', 'number'].
| value: { types: ['string', 'boolean'] }, | |
| value: { type: ['string', 'boolean', 'number'] }, |
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.
[nitpick] Missing semicolon at the end of the statement. This is inconsistent with the code style used elsewhere in the function (lines 101-103).