Open ossiozac opened 3 years ago
I'd just like to add that ReusableStep
will not be reused in the same form. It will be reused on another form on another page.
That's why the label is hard coded within it, and not passed as a prop into it.
Thanks
Hi Thank you for this.And I want to add Autocomplete in this project.But I can't .Please help me. `
export default function Threenumber() { const [addtocart] = useAddToCartMutation(); const [title, setTitle] = useState([]); const { data } = useTakeThreeDateQuery(); const [cityId, setCityId] = useState({ city_id: "" });
return (
); }
export interface FormikStepProps
extends Pick<FormikConfig
export function FormikStep({ children }: FormikStepProps) { return <>{children}</>; }
export function FormikStepper({
children,
...props
}: FormikConfig
function isLastStep() { return step === childrenArray.length - 1; }
return ( <Formik {...props} validationSchema={currentChild.props.validationSchema} onSubmit={async (values, helpers) => { if (isLastStep()) { await props.onSubmit(values, helpers); setCompleted(true); } else { setStep((s) => s + 1); helpers.setTouched({}); } }}
{({ isSubmitting}) => (
{currentChild}
<Grid container spacing={2}>
{step > 0 ? (
<Grid item>
<Button
disabled={isSubmitting}
variant="contained"
color="primary"
onClick={() => setStep((s) => s - 1)}
>
Back
</Button>
</Grid>
) : null}
<Grid item>
<Button
startIcon={
isSubmitting ? <CircularProgress size="1rem" /> : null
}
disabled={isSubmitting}
variant="contained"
color="primary"
type="submit"
>
{isSubmitting ? "Submitting" : isLastStep() ? "Submit" : "Next"}
</Button>
</Grid>
</Grid>
</Form>
)}
</Formik>
); } `
Hi,
Thanks for the wonderful video and for providing all the code.
I am creating a site and would like to make FormikSteps within component so I can reuse them and make sure I keep the code DRY.
The problem I am having is when calling the component which returns a FormikStep inside a FormikStepper, the label and validationSchema don't exist on the parent, therefore the FormikStepper cannot access them.
Please see some example code:
MyForm.js
ReusableStep.js
When in the current state, the validation doesn't work, and the Material UI Step doesn't get a label.
The only way I can get it to work is by passing
validationSchema
andlabel
to theReusableStep
:This is not great, as I would have to repeat defining the schema each time I want to use the FormikStep.
Please could you help me get this sorted?
Many thanks, Zac