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

Bug: Model 与表单结合时,第二次弹窗后,点击弹窗的提交按钮不会触发表单的提交 #4394

Closed
5 tasks done
skyling opened this issue Sep 13, 2024 · 0 comments · Fixed by #4406
Closed
5 tasks done

Comments

@skyling
Copy link

skyling commented Sep 13, 2024

Version

Vben Admin V5

Describe the bug?

当弹窗打开一次关闭后再次打开弹窗,通过Model的onConfirm 触发的await formApi.submitForm();不会执行到Form的handleSubmit.

Reproduction

文件: playground/src/views/examples/modal/form-model-demo.vue

function onSubmit(values: Record<string, any>) {
  message.info(JSON.stringify(values)); // 只会执行一次
}
const [Form, formApi] = useVbenForm({
  handleSubmit: onSubmit,
  schema: [
    {
      component: 'Input',
      componentProps: {
        placeholder: '请输入',
      },
      fieldName: 'field1',
      label: '字段1',
      rules: 'required',
    },

......

const [Modal, modalApi] = useVbenModal({
  fullscreenButton: false,
  onCancel() {
    modalApi.close();
  },
  onConfirm: async () => {
    await formApi.submitForm();
    modalApi.close();
  },
  onOpenChange(isOpen: boolean) {
    if (isOpen) {
      const { values } = modalApi.getData<Record<string, any>>();
      if (values) {
        formApi.setValues(values);
      }
    }
  },
  title: '内嵌表单示例',
});

除非在onOpenChange 中重新设置setState

onOpenChange(isOpen: boolean) {
    if (isOpen) {
      const { values } = modalApi.getData<Record<string, any>>();
      formApi.setState({ handleSubmit: onSubmit });
      if (values) {
        formApi.setValues(values);
      }
    }
  },

System Info

node 22.7.0

Relevant log output

No response

Validations

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant