Merge lp:~huwshimi/lazr-js/autocomplete-enter-580404 into lp:lazr-js

Proposed by Huw Wilkins
Status: Merged
Approved by: Huw Wilkins
Approved revision: 205
Merged at revision: 204
Proposed branch: lp:~huwshimi/lazr-js/autocomplete-enter-580404
Merge into: lp:lazr-js
Diff against target: 15 lines (+4/-1)
1 file modified
src-js/lazrjs/autocomplete/autocomplete.js (+4/-1)
To merge this branch: bzr merge lp:~huwshimi/lazr-js/autocomplete-enter-580404
Reviewer Review Type Date Requested Status
Brad Crittenden (community) code Approve
Benji York (community) code* Approve
Review via email: mp+49351@code.launchpad.net

Commit message

Pressing enter in an autocomplete field now submits the form when there are no suggestions.

Description of the change

Pressing enter in an autocomplete field now submits the form when there are no suggestions.

TO TEST:

View a bug page. Click the edit button or "Add tags". Type in a tag name. Press ENTER.

The form should submit and the tags will be saved. You used to have to press ENTER twice to get this to happen.

To post a comment you must log in.
Revision history for this message
Martin Pool (mbp) wrote :

s/wat/want

What happens if this.get(QUERY) is actually null? Won't this error? Or maybe that can never happen if ._last_input_completed is false?

I see this code was already in the keydown method and I'm just a bit curious why it's there. Does it need to happen on keydown to stop the default behaviour happening?

204. By Huw Wilkins

Fixed comment grammar.

Revision history for this message
Martin Pool (mbp) wrote :

So if I've typed the start of a unique string, the first enter will complete the string and the second will submit?

Does this make it impossible to enter a prefix of an official tag as a new tag?

(I guess I should just run up the branch at this point.)

Thanks for addressing this, the current situation does grate.

Revision history for this message
Benji York (benji) wrote :

In testing the branch I couldn't trigger the autocomplete behavior at all, but the change did appear to work as advertised (i.e., a single enter caused the new tag value to be saved). Upon inspection I can't see any problem with the patch as given.

I would like to see a test for this behavior to prevent a regression, but I don't know what the state of our tests of browser behavior is currently so, unfortunately, that may not be practical.

review: Approve (code*)
Revision history for this message
Brad Crittenden (bac) wrote :

After setting up some official tags for a project I tested autocomplete and it worked pretty well. I did discover an issue while using a Webkit browser (Safari) that does not appear under Firefox:

Create an offical tag "reallylong".

Try to add a tag "long". When "long" is entered, autocomplete suggests "reallylong". To *not* accept the suggestion enter a space. Upon doing so in Safari the 'accept' and 'cancel' icons disappear and pressing return has no affect. The only way to recover is to press ESC and the entry is cancelled.

I don't know if this problem is introduced by your branch. Please either fix as part of your branch or open a new bug. I'm marking the branch Approved so you can do either at your discretion.

review: Approve (code)
Revision history for this message
Huw Wilkins (huwshimi) wrote :

@Martin
> I see this code was already in the keydown method and I'm just a bit curious why it's there. Does it need to happen on keydown to stop the default behaviour happening?

Where else would this code live? On keyup? I don't know why this code lives in keydown as opposed to keyup.

> Does this make it impossible to enter a prefix of an official tag as a new tag?

Yes, in a way. You can not press enter to save the form if you have any suggestions. In the prefix case you would have to enter a space in those circumstances. However, this is not a regression introduced by this branch.

@Brad
Will try and test that. I suspect it is a different issue.

Revision history for this message
Huw Wilkins (huwshimi) wrote :

@Brad
Actually I think I'm wrong it looks like it is an issue with my branch. Will fix.

205. By Huw Wilkins

Fixed error when the field contained a trailing space.

Revision history for this message
Huw Wilkins (huwshimi) wrote :

@Brad that is fixed. There was an error when there was a trailing space. My guess is that safari handles errors differently and was killing the javascript after the error.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src-js/lazrjs/autocomplete/autocomplete.js'
2--- src-js/lazrjs/autocomplete/autocomplete.js 2011-01-14 14:52:37 +0000
3+++ src-js/lazrjs/autocomplete/autocomplete.js 2011-03-01 01:07:20 +0000
4@@ -723,7 +723,10 @@
5 _onInputKeydown: function(e) {
6 // Is this one of our completion keys; Tab, or Enter?
7 if (e.keyCode === TAB || e.keyCode === RETURN) {
8- if (this.get(QUERY) !== null && !this._last_input_was_completed) {
9+ /* Check that the last string was not completed and that there are
10+ matching queries (we don't want to try and complete the input if
11+ there are no matches). */
12+ if (this.get(QUERY) !== null && !this._last_input_was_completed && this.findMatches(this.get(QUERY).text).length !== 0) {
13 // The user has an active query in the input box.
14 this.completeInput();
15 // Keep the tab key from switching focus away from the input

Subscribers

People subscribed via source and target branches