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:在useVbenModal中使用From表单,在onOpenChange中调用formApi中的setState会报错 #5400

Closed
5 tasks done
kongchengxinde opened this issue Jan 15, 2025 · 0 comments · Fixed by #5406
Closed
5 tasks done

Comments

@kongchengxinde
Copy link

Version

Vben Admin V5

Describe the bug?

在useVbenModal中使用From表单,在onOpenChange中调用formApi中的setState会报错:this.form?.setFieldValue is not a function
image
我当前的解决方法是在formApi.setState外层加一个计时器可以解决

Reproduction

<script lang="ts" setup>
import { useVbenForm, useVbenModal } from '@vben/common-ui';

import { ElButton } from 'element-plus';

const [Form, formApi] = useVbenForm({
  commonConfig: {
    // 所有表单项
    componentProps: { class: 'w-full' },
  },
  layout: 'horizontal',
  wrapperClass: 'grid-cols-1',
  schema: [
    {
      component: 'Input',
      fieldName: 'field',
      label: '测试节点',
    },
  ],
});

const [Modal, modalApi] = useVbenModal({
  onCancel() {
    modalApi.close();
  },
  async onOpenChange(isOpen: boolean) {
    if (isOpen) {
      formApi.setState((prev) => ({
        schema: prev.schema?.filter((item) => item.fieldName !== 'field'),
      }));
    }
  },
});

const openModal = () => {
  modalApi.open();
};
</script>
<template>
  <div>
    <Modal class="w-[500px]" title="添加分类">
      <Form />
    </Modal>
    <ElButton @click="openModal()">打开窗口</ElButton>
  </div>
</template>

System Info

OS: macOS 15.1.1
CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
Google Chrome: 最新版本

Relevant log output

No response

Validations

@github-actions github-actions bot locked and limited conversation to collaborators Jan 30, 2025
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