0

我正在使用以下内容来防止其他输入字段的默认设置,但似乎在我的 DayPickerInput 上无法完全正常工作。

//防止默认功能

onKeyPress = (event) => {

  event.preventDefault();

}

//DayPicker输入

    <DateObject

        inputProps={

          {className: 'pl2 br3 shadow-1 dropdownButtonDate', onKeyPress: this.onKeyPress}

        }

        value={selectedDay}

        onDayChange={this.handleDayChange}

        dayPickerProps={{

          selectedDays: selectedDay,

          disabledDays: [{

            daysOfWeek: [0, 6],

          },

          {

            before: new Date(this.dateRestriction())

          }]

        }}

     />

它不让我写任何东西,这太棒了!

但是当我试图删除我的日期时,它允许我这样做。

我怎么能阻止这种行为?

4

1 回答 1

0

After tweaking it, I found my own solution.

Use "onKeyDown" instead of "onKeyPress" for DayPickerInput. OnKeyPress to preventDefault() will prevent writing on the input field, but will still allow delete.

The modification below worked and I can no longer delete the date that was picked, nor write on it.

    inputProps={

      {className: 'pl2 br3 shadow-1 dropdownButtonDate', onKeyDown: this.onKeyPress}

    }

Note: You can still select a new date to replace the value.

于 2018-11-06T19:07:44.210 回答