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: solve the error about setFieldValue array & pref the code #3775

Merged
merged 2 commits into from
Apr 23, 2024

Conversation

electroluxcode
Copy link
Contributor

fix #3774 & pref the code

@doraemonxxx
Copy link
Contributor

Hello. Will this modification affect other functionalities and behavior, as it seems that you have removed core functions from the "useFormEvents" hook?

@electroluxcode
Copy link
Contributor Author

electroluxcode commented Apr 22, 2024

Hello. Will this modification affect other functionalities and behavior, as it seems that you have removed core functions from the "useFormEvents" hook?

Probably not, because the original purpose of this code is to get the key valve on the object or array 's path, such as "a.b.c", but this has a problem, such as "a[0]" code it does not recognize(#3774). So here I use Lodash's get function to replace the original tryConstructArray and tryConstructObject function, which is compatible with object and array syntax.

And elsewhere in vben-admin, using Lodash get and set also seems to be a common behavior。
Another point is that the tryConstructArray and tryConstructObject methods are not used elsewhere

@doraemonxxx
Copy link
Contributor

doraemonxxx commented Apr 22, 2024

Thank you for the explanation 😃

@wangjue666 wangjue666 merged commit f5cd3ad into vbenjs:main Apr 23, 2024
2 checks passed
@PoteXB
Copy link

PoteXB commented May 8, 2024

这个代码导致我之前所有的 类似 field: '[startTime, endTime]', 这种setFieldsValue 赋值不了了
const [registerForm, { validate, setFieldsValue, getFieldsValue }] = useForm({
colon: true,
baseRowStyle: { padding: '10px' },
baseColProps: { span: 24 },
labelWidth: 124,
schemas: [
{
field: '[startTime, endTime]',
label: '上架时间',
component: 'RangePicker',
componentProps: {
placeholder: ['开始时间', '结束时间'],
showTime: {
defaultValue: [dayjs('00:00:00', 'HH:mm:ss'), dayjs('00:00:00', 'HH:mm:ss')],
},
},
itemProps: {
extra: (


开始时间:在用户端上架展示该活动,不代表报名时间;

结束时间:在用户端下架该活动,不再展示;


),
},
required: true,
},
],
showActionButtonGroup: false,
});

setFieldsValue({
startTime: "2024-12-01 11:11:11",
endTime: "2024-12-03 11:11:11",
});
这种setFieldsValue 我以前是可以正常赋值的 , 现在不行了

@PoteXB
Copy link

PoteXB commented May 8, 2024

@electroluxcode @doraemonxxx 希望能解决下

@doraemonxxx
Copy link
Contributor

Hi, can you please pull the latest revisions? I think it should be fixed in commit 88e77db

@doraemonxxx
Copy link
Contributor

I think you should use resetDefaultField instead of setFieldsValue

@PoteXB
Copy link

PoteXB commented May 8, 2024

你好,请问可以拉一下最新版本吗?我认为它应该在提交88e77db中修复

Still can't do it , I used setFieldsValue before when editing detailed data

@electroluxcode
Copy link
Contributor Author

electroluxcode commented May 8, 2024

my fault,确实没考虑一个表单项传递复数值的情况,可以先提一个issue,一会儿我会看看怎么修复

@PoteXB
Copy link

PoteXB commented May 8, 2024

你好,请问可以拉一下最新版本吗?我认为它应该在提交88e77db中修复

@doraemonxxx @electroluxcode
image
image

This is from before
image

This is the now
image

@doraemonxxx
Copy link
Contributor

doraemonxxx commented May 8, 2024

I see, you are setting the value not resetting. for now the workaround for that issue is to revert the latest code to the original one. you can just copy or use old one and replace the new one from this website. go to Files changed

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.

[BUG]:form表单使用setFieldValue 的 field 是数组的时候并不生效
4 participants