Opened 4 years ago

Last modified 4 years ago

#11052 reopened feature

Autocomplete: Trigger change event when return is pressed

Reported by: pl_fidessa Owned by:
Priority: minor Milestone: none
Component: ui.autocomplete Version: 1.11.2
Keywords: Cc:
Blocked by: Blocking:

Description

The change events for the autocomplete widget are subtly different from a plain text box.

A text box raises change events if:

  • the content is changed and focus leaves the control
  • the content is changed and return is pressed (just before the submit event of the form)

The autocomplete control only raises a change event when focus leaves the control.

This can be seen in the following jsfiddle: http://jsfiddle.net/pl_fidessa/24yzmq1a/. The bottom div displays the events that are triggered, so just type into a control and press return to see what events are raised.

Note that the behaviour in IE9 seems to be a bit different (although I'd argue still incorrect). As far as I can tell pressing return moves focus away from the control, so you see a submit event for the form, then a change event for the autocomplete control.

What I'd like is for the behaviour of the autocomplete widget to be the same as the text box. i.e. if you change the value then press return (without having focus on the dropdown menu), then a change event is triggered immediately. If that's something you're willing to consider than I can format up a patch and submit a pull request.

Version information:

Tested with:

  • JQuery 2.1.0
  • JQuery 1.11.2 (though the code in the mainline is the same as far as I can tell)
  • Chrome 40.0.2214.111 m on Windows 7 (similar behaviour seen in Firefox, IE9 behaviour differs as described above)

Many thanks,

Paul.

Change History (3)

comment:1 Changed 4 years ago by Scott González

Resolution: notabug
Status: newclosed

comment:2 in reply to:  1 Changed 4 years ago by pl_fidessa

Replying to scott.gonzalez:

See http://contribute.jquery.org/wont-fix/#change-event and #8878.

Hi Scott,

Sorry, I think I've probably used the wrong terminology in my initial report since #8878 seems to specifically be about the native change event vs the autocompletechange event.

I am using the autocompletechange event on the autocomplete widget, and am proposing that you fire an autocompletechange event when return is pressed. I'm not using the native change event for anything on the autocomplete widget.

Do you still consider this to be "notabug"?

Thanks,

Paul

comment:3 Changed 4 years ago by Scott González

Resolution: notabug
Status: closedreopened
Summary: autocomplete does not raise a change event when return is pressed.Autocomplete: Trigger change event when return is pressed
Type: bugfeature

I'd say this is a feature request, since the intention of the event is pretty clearly documented: "Triggered when the field is blurred, if the value has changed." I'll reopen for others to weigh in.

Note: See TracTickets for help on using tickets.