我目前正在努力使用“自动生成链接”按钮。单击后,“链接”字段应填写数据“ http://predefinedlink.com ”
由于这里使用了 Formik + Material UI 的组合,我很难做到这一点。
const useStyles = makeStyles((theme) => ({[...]}));
const EventStream = ({ onSubmit, eventStream }) => {
const classes = useStyles();
return (
<Formik
initialValues={{
link: maybe(() => eventStream.link, "") || "",
}}
onSubmit={onSubmit}
validateOnBlur={false}
validateOnChange={false}
enableReinitialize
>
{({ handleSubmit, isSubmitting, dirty }) => (
<FormikForm autoComplete="off" noValidate>
<Card>
<CardContent>
<Grid container spacing={3}>
<Grid xs={12} item>
<Field name="link" label="Link" component={TextField} />
<button
onClick={console.log("Fill TextField 'link' with new data")}
>
Auto generate link »
</button>
</Grid>
</Grid>
</CardContent>
<CardActions className={classes.cardActions}>
<Button
variant="contained"
color="primary"
classes={{
root: clsx(classes.saveButton, {
[classes.saveButtonDirty]: !dirty,
}),
disabled: isSubmitting && classes.saveButtonDisabled,
}}
disabled={isSubmitting || !dirty}
onClick={handleSubmit}
>
Save
{isSubmitting && (
<CircularProgress
size={20}
thickness={5}
color="inherit"
className={classes.saveButtonProgress}
/>
)}
</Button>
</CardActions>
</Card>
</FormikForm>
)}
</Formik>
);
};
export default EventStream;