【问题标题】:Material UI TextField with type datetime-local date picker with secondsMaterial UI TextField 类型为 datetime-local 日期选择器和秒
【发布时间】:2021-12-29 07:10:24
【问题描述】:

我正在使用 react-admin 并想使用 DateTimeInput 编辑日期和时间,包括秒数。但是,我无法做到这一点。我尝试了以下操作:

选项 1:

<TextField
  id={id}
  {...input}
  step='1'
  value={format(input.value) || ''}
  variant={variant}
  error={!!(touched && (error || submitError))}
  helperText={<InputHelperText touched={touched ?? false} error={error || submitError} helperText={helperText} />}
  label={<FieldTitle label={label} source={source} resource={resource} isRequired={isRequired} />}
  {...options}
  {...sanitizeInputRestProps(rest)}
/>

选项 2:

<DateTimeInput label='Scratched Time' source='scratched_time' disabled={!scratched} />

但是,我无法编辑秒字段。

【问题讨论】:

  • MUI的DateTimePicker不可以,只有TimePicker支持设置秒数mui pickers docs

标签: reactjs material-ui react-admin


【解决方案1】:

尝试将“step”放在“inputProps”中。 ;-)

<TextField 
    inputProps={{
        "step": 1,
    }}
    type="datetime-local"
/>

Example

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-10-23
    • 1970-01-01
    • 2019-08-23
    • 1970-01-01
    • 1970-01-01
    • 2021-12-15
    • 2017-10-26
    相关资源
    最近更新 更多