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

弹出层表单a-modal嵌套a-form,使用modal自带的确认按钮@ok事件去校验表单然后通过通过接口保存,在生产环境校验表单,表单出现校验文字之后会自动关闭弹框 #1038

Closed
chello-g opened this issue Apr 25, 2022 · 4 comments

Comments

@chello-g
Copy link

场景: 弹出层表单a-modal嵌套a-form,使用modal自带的确认按钮@ok事件去校验表单然后通过接口保存表单数据。
问题:在本地环境,没有写表单的必填项,点击确定按钮,出现校验文字,弹框不会关闭,但是同样的代码,在生产环境出现校验文字之后弹框会自动关闭。
解决:@ok事件改为@before-ok事件,就解决了,why

@qingtiantongxie
Copy link

@ok 就是 modal 确认按钮的默认事件 你调用 则 modal 就会关闭
如果想要实现异步关闭 请使用on-before-ok 属性或者 @before-ok 在校验失败调用 done(false)

@chello-g
Copy link
Author

官方文档最下方API中并没有写@before-ok事件,只在一个demo中含有@before-ok事件,建议文档可以更新添加一下。本地环境也是异步调用接口后关闭,@ok事件却可以使用,没有出现上述描述问题,发布到线上就出现了上述问题。

@flsion flsion closed this as completed Jul 17, 2022
@xuhui1998
Copy link

可以通过插槽<template #footer>自定义底部按钮

@a2cd
Copy link

a2cd commented Jan 5, 2025

被折磨惨了,基础不牢地动山摇,感谢大佬!
@ok改成了@before-ok

const handleConfirm = async () => {
  // 验证通过返回undefined,验证不通过会返回具体错误
  const errors = await idInfoFormRef.value.validate(); // 这里返回的是个Promise,一定要await
  if(errors) {
    return false; // 返回false对话框就不会自动关闭
  }

  idInfoModelOkLoading.value = true;
  try {
    await changeIdInfo(idInfoForm);
    idInfoModelVisible.value = false;
    Message.success('编辑成功')
  } catch (e) {
  } finally {
    idInfoModelOkLoading.value = false;
  }
};

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

No branches or pull requests

5 participants