slow-yellowS
Refine3y ago
4 replies
slow-yellow

Display the date in a TextField within an <Edit> component (MUI)

How can I correctly display the date in a TextField within an <Edit> component? The API returns a value of '2023-07-25T03:00:00.000Z' for the 'start_date' attribute, but I'm not sure how to format this for the TextField. I get a warning that this value doesn't conform to the required format, 'yyyy-MM-dd'. Here is my current code:

``jsx <Grid item xs={12} md={6} lg={3}> <TextField {...register("start_date", { validate: (value) => { return new Date(value).getTime() > new Date().getTime() ? ${type ?? ""} ${translate("customers.validate.start_date")} : true; }, valueAsDate: true, })} error={!!(errors as any)?.start_date} helperText={(errors as any)?.start_date?.message} margin="normal" fullWidth type="date" InputLabelProps={{ shrink: true }} label={${type ?? ""} ${translate("customers.fields.start_date")}`}
name="start_date"
/>
</Grid>
Was this page helpful?