admin管理员组文章数量:1415100
My objective is to disable the past days and should not allow you to select, I've tried but didn't worked.
Here is the code:
<TextField
variant="outlined"
id="datetime-local"
label="Select Date and Time"
placeholder="Select Date and Time"
type="datetime-local"
value={this.state.DateTime}
InputLabelProps={{
shrink: true,
}}
onChange={this.HandleChange}
/>
Don't know where I'm going wrong. Can anyone help me in this query?
My objective is to disable the past days and should not allow you to select, I've tried but didn't worked.
Here is the code:
<TextField
variant="outlined"
id="datetime-local"
label="Select Date and Time"
placeholder="Select Date and Time"
type="datetime-local"
value={this.state.DateTime}
InputLabelProps={{
shrink: true,
}}
onChange={this.HandleChange}
/>
Don't know where I'm going wrong. Can anyone help me in this query?
Share Improve this question edited Apr 10, 2021 at 8:37 NearHuscarl 82.2k24 gold badges320 silver badges282 bronze badges asked Apr 10, 2021 at 8:17 SanjanaSanjana 2962 gold badges8 silver badges21 bronze badges1 Answer
Reset to default 6To disable the previous date, you can use the min
attribute of input
. Here is how you disallow dates before 2021-02-20T00:00
:
<TextField
type="datetime-local"
inputProps={{
min: "2021-02-20T00:00"
}}
/>
To disable previous dates, you can instantiate a new Date
object, which defaults to current date and pass it to the min
attribute:
<TextField
type="datetime-local"
inputProps={{
// only needs the first 16 characters in the date string
min: new Date().toISOString().slice(0, 16),
}}
/>
Live Demo
本文标签: javascriptMaterialUI How to disable previous dates in the datetimelocal TextFieldStack Overflow
版权声明:本文标题:javascript - Material-UI: How to disable previous dates in the datetime-local TextField - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745182809a2646544.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论