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

FEATURE: add an API for quickly set the submitting state in formApi #4985

Open
3 tasks done
richex-cn opened this issue Nov 29, 2024 · 1 comment
Open
3 tasks done

Comments

@richex-cn
Copy link
Contributor

Version

Vben Admin V5

Description

before:

const [Form, formApi] = useVbenForm({
  // ...
  handleSubmit: async params => {
    // show loading and disable input when submitting
    formApi.setState({
      commonConfig: { disabled: true },
      resetButtonOptions: { disabled: true },
      submitButtonOptions: { loading: true },
    })

    await requestSubmit(params)

    // submitted
    formApi.setState({
      commonConfig: { disabled: false },
      resetButtonOptions: { disabled: false },
      submitButtonOptions: { loading: false },
    })
  },
})

after:

const [Form, formApi] = useVbenForm({
  // ...
  handleSubmit: async params => {
    // show loading and disable input when submitting
    formApi.setSubmittingState(true)

    await requestSubmit(params)

    // submitted
    formApi.setSubmittingState(false)
  },
})

Proposed Solution

add an API for quickly set the submitting state in formApi, e.g. formApi.setSubmittingState(<boolean>)

Alternatives Considered

No response

Additional Context

No response

Validations

  • Read the docs
  • Ensure the code is up to date. (Some issues have been fixed in the latest version)
  • I have searched the existing issues and checked that my issue does not duplicate any existing issues.
@finalreturn
Copy link

Modal和Drawer 也有这种类似的需求。
例如:Modal或者Drawer嵌套表单,在提交表单时,类似的状态设置如下:内容遮罩loading、取消按钮禁用、确认按钮的loading、开启支持键盘 esc (提交表单时按下无效)

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

No branches or pull requests

2 participants