Kendo UI Datepicker disable typing

前端 未结 10 1677
挽巷
挽巷 2020-12-29 02:34

I want users to be able to change a Kendo UI Datepicker value only through its button and selecting the date from the pop-up. How can I prevent users from typing in the Date

相关标签:
10条回答
  • 2020-12-29 03:06

    On your input element add this attribute and value...

    onkeydown="return false;"
    

    This will disable typed input and still allow using the calendar control input.

    0 讨论(0)
  • 2020-12-29 03:07

    Indeed, the widget does not restrict user while typing in the input. The reason for this behavior is explained here: Why widget does not restrict typing

    Along with all other solutions shared in this thread, the one can create a custom Masked DatePicker, which will restrict the user to a specific date format. Check this how-to demo for more details:

    Create Date Masking

    **Note that this is not supported by Kendo UI as a built-in feature, hence you will need to use it on your own risk. The good news is that it works pretty good without known side effects.

    0 讨论(0)
  • 2020-12-29 03:11
    .HtmlAttributes(new { onkeydown="return false" })
    
    0 讨论(0)
  • 2020-12-29 03:18

    Justin's answer works, but it doesn't prevent a right mouse-click from pasting an incorrect value. You could use the oncontextmenu to prevent a right mouse-click

    oncontextmenu="return false;"
    

    This would also prevent the number in the calendar from being copied though.

    0 讨论(0)
提交回复
热议问题