Modify jQuery autocomplete not to submit eagerly on Enter

后端 未结 4 1040
悲哀的现实
悲哀的现实 2021-01-14 22:55

Our users complain that when they press the enter key after pasting or typing values in a jQuery autocomplete widget the form is submitted.

It\'s extremely annoyin

4条回答
  •  独厮守ぢ
    2021-01-14 23:52

    I was somehow against overriding the jqueryui implementation and did the following:

    • in the close event of the autocomplete i set a flag "doNotSubmit" when enter was pressed
    • in your case then i'd bound a submit event listener to the form which checks the doNotSubmit flag and acts accordingly.

    The basic idea behind it, is that jqueryui's close event is triggered before keyup or submit events and gives you the keycode. So you can in another place (keyup, submit, etc.) consume that one unwanted enter or other keypress.

提交回复
热议问题