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

fix(Form): fix nesting name underline error #3095

Merged
merged 6 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/form/FormItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ const FormItem = forwardRef<FormItemInstance, FormItemProps>((originalProps, ref
const snakeName = []
.concat(formListName, name)
.filter((item) => item !== undefined)
.join('_'); // 转化 name
.toString(); // 转化 name

const errorMessages = useMemo(() => errorMessage ?? globalFormConfig.errorMessage, [errorMessage, globalFormConfig]);

Expand Down
2 changes: 1 addition & 1 deletion src/form/FormList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const FormList: React.FC<TdFormListProps> = (props) => {
const snakeName = []
.concat(name)
.filter((item) => item !== undefined)
.join('_'); // 转化 name
.toString(); // 转化 name

const isMounted = useRef(false);

Expand Down
5 changes: 4 additions & 1 deletion src/form/hooks/useFormItemStyle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,11 @@ export default function useFormItemStyle(props) {
return extra;
}, [showErrorMessage, errorList, successList, tips, classPrefix]);

// snake 在dom上显示的名字改成下划线拼接
const formSnakeName = snakeName.split(',').join('_');

const formItemClass = classNames(`${classPrefix}-form__item`, className, {
[`${classPrefix}-form-item__${snakeName}`]: snakeName,
[`${classPrefix}-form-item__${formSnakeName}`]: formSnakeName,
[`${classPrefix}-form__item-with-help`]: helpNode,
[`${classPrefix}-form__item-with-extra`]: extraNode,
});
Expand Down
4 changes: 2 additions & 2 deletions src/form/hooks/useInstance.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ function formatValidateResult(validateResultList) {
}

// 整理嵌套数据
if (result[key] && key.includes('_')) {
const keyList = key.split('_');
if (result[key] && key.includes(',')) {
const keyList = key.split(',');
const fieldValue = calcFieldValue(keyList, result[key]);
merge(result, fieldValue);
delete result[key];
Expand Down
Loading