feat:【antd/ele】使用 productSpuIds 和 productCategoryIds 自定义插槽的表单在验证前同步 formData 中的值到表单中
This commit is contained in:
@@ -49,6 +49,19 @@ const [Form, formApi] = useVbenForm({
|
|||||||
|
|
||||||
const [Modal, modalApi] = useVbenModal({
|
const [Modal, modalApi] = useVbenModal({
|
||||||
async onConfirm() {
|
async onConfirm() {
|
||||||
|
// 同步商品/分类选择到表单,确保验证时能获取到值
|
||||||
|
if (formData.value.productSpuIds) {
|
||||||
|
await formApi.setFieldValue(
|
||||||
|
'productSpuIds',
|
||||||
|
formData.value.productSpuIds,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (formData.value.productCategoryIds) {
|
||||||
|
await formApi.setFieldValue(
|
||||||
|
'productCategoryIds',
|
||||||
|
formData.value.productCategoryIds,
|
||||||
|
);
|
||||||
|
}
|
||||||
const { valid } = await formApi.validate();
|
const { valid } = await formApi.validate();
|
||||||
if (!valid) {
|
if (!valid) {
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -52,9 +52,21 @@ const [Form, formApi] = useVbenForm({
|
|||||||
|
|
||||||
const [Modal, modalApi] = useVbenModal({
|
const [Modal, modalApi] = useVbenModal({
|
||||||
async onConfirm() {
|
async onConfirm() {
|
||||||
// 在验证前同步 formData.rules 到表单中
|
// 在验证前同步 formData 中的值到表单中
|
||||||
// TODO @puhui999:选择了分类、或者商品,还是报没选择;
|
|
||||||
await formApi.setFieldValue('rules', formData.value.rules || []);
|
await formApi.setFieldValue('rules', formData.value.rules || []);
|
||||||
|
// 同步商品/分类选择到表单,确保验证时能获取到值
|
||||||
|
if (formData.value.productSpuIds) {
|
||||||
|
await formApi.setFieldValue(
|
||||||
|
'productSpuIds',
|
||||||
|
formData.value.productSpuIds,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (formData.value.productCategoryIds) {
|
||||||
|
await formApi.setFieldValue(
|
||||||
|
'productCategoryIds',
|
||||||
|
formData.value.productCategoryIds,
|
||||||
|
);
|
||||||
|
}
|
||||||
const { valid } = await formApi.validate();
|
const { valid } = await formApi.validate();
|
||||||
if (!valid) {
|
if (!valid) {
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -49,6 +49,19 @@ const [Form, formApi] = useVbenForm({
|
|||||||
|
|
||||||
const [Modal, modalApi] = useVbenModal({
|
const [Modal, modalApi] = useVbenModal({
|
||||||
async onConfirm() {
|
async onConfirm() {
|
||||||
|
// 同步商品/分类选择到表单,确保验证时能获取到值
|
||||||
|
if (formData.value.productSpuIds) {
|
||||||
|
await formApi.setFieldValue(
|
||||||
|
'productSpuIds',
|
||||||
|
formData.value.productSpuIds,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (formData.value.productCategoryIds) {
|
||||||
|
await formApi.setFieldValue(
|
||||||
|
'productCategoryIds',
|
||||||
|
formData.value.productCategoryIds,
|
||||||
|
);
|
||||||
|
}
|
||||||
const { valid } = await formApi.validate();
|
const { valid } = await formApi.validate();
|
||||||
if (!valid) {
|
if (!valid) {
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -52,8 +52,21 @@ const [Form, formApi] = useVbenForm({
|
|||||||
|
|
||||||
const [Modal, modalApi] = useVbenModal({
|
const [Modal, modalApi] = useVbenModal({
|
||||||
async onConfirm() {
|
async onConfirm() {
|
||||||
// 在验证前同步 formData.rules 到表单中
|
// 在验证前同步 formData 中的值到表单中
|
||||||
await formApi.setFieldValue('rules', formData.value.rules || []);
|
await formApi.setFieldValue('rules', formData.value.rules || []);
|
||||||
|
// 同步商品/分类选择到表单,确保验证时能获取到值
|
||||||
|
if (formData.value.productSpuIds) {
|
||||||
|
await formApi.setFieldValue(
|
||||||
|
'productSpuIds',
|
||||||
|
formData.value.productSpuIds,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (formData.value.productCategoryIds) {
|
||||||
|
await formApi.setFieldValue(
|
||||||
|
'productCategoryIds',
|
||||||
|
formData.value.productCategoryIds,
|
||||||
|
);
|
||||||
|
}
|
||||||
const { valid } = await formApi.validate();
|
const { valid } = await formApi.validate();
|
||||||
if (!valid) {
|
if (!valid) {
|
||||||
return;
|
return;
|
||||||
|
|||||||
Reference in New Issue
Block a user