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

feat(FormControl): support ruleDependencies #3729

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

Conversation

myNameIsDu
Copy link
Member

@myNameIsDu myNameIsDu commented Apr 7, 2024

before

Kapture.2024-04-07.at.17.08.22.mp4

after

Kapture.2024-04-07.at.17.10.41.mp4

Copy link

codesandbox bot commented Apr 7, 2024

Review or Edit in CodeSandbox

Open the branch in Web EditorVS CodeInsiders

Open Preview

Copy link

vercel bot commented Apr 7, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
rsuite-nextjs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 8, 2024 1:21pm
rsuite-storybook ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 8, 2024 1:21pm
1 Ignored Deployment
Name Status Preview Comments Updated (UTC)
rsuite-v4 ⬜️ Ignored (Inspect) Visit Preview Apr 8, 2024 1:21pm

Copy link

vercel bot commented Apr 7, 2024

@myNameIsDu is attempting to deploy a commit to the rsuite Team on Vercel.

A member of the Team first needs to authorize it.

Copy link

codesandbox-ci bot commented Apr 7, 2024

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

@myNameIsDu myNameIsDu requested a review from simonguo April 7, 2024 09:30
src/Form/Form.tsx Outdated Show resolved Hide resolved
Comment on lines 233 to 243
const checkedErrors = checkFieldNames.reduce((acc, checkFieldName) => {
const checkResult = model?.checkForField(checkFieldName, nextFormValue);
if (checkResult.hasError) {
acc[checkFieldName] = checkResult.errorMessage || checkResult;
}
return acc;
}, {} as Record<string, ReactNode>);
const nextError = {
...omit(formError, checkFieldNames),
...checkedErrors
};
Copy link
Member

Choose a reason for hiding this comment

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

This code has a high degree of duplication with the code in then, and it is best to abstract out the reused code.

Copy link
Member Author

Choose a reason for hiding this comment

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

done

@@ -193,6 +193,7 @@ cleanErrorForField: (fieldName: keyof E, callback?: () => void) => void;
| plaintext | boolean | Make the control plaintext. |
| readOnly | boolean | Make the control readonly. |
| rule | checkType | Current field verification rule. If it conflicts with the `<Form>`'s `model`, it get higher priority, [example](/components/form-validation/#field-level-verification-rules). |
| ruleDependencies | string[] | The dependent fields for the check. |
Copy link
Member

Choose a reason for hiding this comment

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

Add version badge:

The dependent fields for the check. <br/>![](https://img.shields.io/badge/min-v5.50.0-blue)

Copy link
Member Author

Choose a reason for hiding this comment

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

done

@@ -180,8 +180,10 @@ cleanErrorForField: (fieldName: keyof E, callback?: () => void) => void;
| plaintext | boolean | 使控件为纯文本。 |
| readOnly | boolean | 使控件为只读。 |
| rule | checkType | 当前字段的校验规则,如果与`<Form>`的`model`冲突,以当前为准,[示例](/zh/components/form-validation/#field-级别的校验规则)。 |
| ruleDependencies | string[] | 校验依赖的字段。 |
Copy link
Member

Choose a reason for hiding this comment

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

Add version badge:

校验依赖的字段。 <br/>![](https://img.shields.io/badge/min-v5.50.0-blue)

Copy link
Member Author

Choose a reason for hiding this comment

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

done

@@ -71,6 +73,9 @@ export interface FormControlProps<P = any, ValueType = any>

/** Validation rule */
rule?: CheckType<unknown, any>;

/** The dependent fields for the check */
Copy link
Member

Choose a reason for hiding this comment

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

Indicate version

/**
 * The dependent fields for the check.
 * @version 5.60.0 
 */

Copy link
Member Author

Choose a reason for hiding this comment

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

done

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.

None yet

2 participants