ant-design / ant-design/sunflower
useStepFrom Steps onChange bug
- Dominant language
- TypeScript
- Stars
- 490
- Forks
- 42
- PR merge metrics
- No merged PRs in 30d
Description
```javascript
import React from 'react'
import { useStepsForm } from 'sunflower-antd'
import { Steps, Input, Button, Form, Result } from 'antd'
const { Step } = Steps
const layout = {
labelCol: { span: 8 },
wrapperCol: { span: 16 },
}
const tailLayout = {
wrapperCol: { offset: 8, span: 16 },
}
const Example = () => {
const { form, current, gotoStep, stepsProps, formProps, submit, formLoading } = useStepsForm({
async submit(values) {
const { username, email, address } = values
console.log(username, email, address)
await new Promise((r) => setTimeout(r, 1000))
return 'ok'
},
total: 4,
})
const formList = [
<>
gotoStep(current + 1)}>Next
,
<>
gotoStep(current + 1)}>Next
gotoStep(current - 1)}>Prev
,
<>
{
submit().then((result) => {
if (result === 'ok') {
gotoStep(current + 1)
}
})
}}>
Submit
gotoStep(current - 1)}>Prev
,
]
return (
{formList[current]}
{current === 3 && (
{
form.resetFields()
gotoStep(0)
}}>
Buy it again
Check detail
}
/>
)}
)
}
export default Example
```
In a scenario where I have more than two form fields, it sends the form ignoring the required fields because I can change it by clicking on the Steps.
It is a necessary behavior for users to change the form by clicking on it. In this case, the stepper structure does not work properly.
Only when I disable the onChange I can I get the form completely. But I don't think this is the best method.
Thank you for your help.
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with the useStepsForm hook and the stepsProps onChange behavior shown in the issue's example, then reproduce the case by clicking Steps while required fields are empty. Done means users can navigate by clicking the steps without allowing submission to bypass required-field validation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, react
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100