Problem/Motivation

I'm on drupal.org commenting on an issue, or in general using a node edit form in Drupal.

I want to change one of the tags from the existing "Needs Documentation" to "Needs Update Documentation". It's in the middle of a list of tags the issue has been tagged with. Let's say the list is API Change, Needs Documentation, UI Freeze.

I go to where Needs Documentation is and start typing Update in the middle of that tag.

In Drupal 7: I get a type-ahead drop-down box, but it contains suggestions for the UI Freeze tag, not the tag I am actually editing.

In Drupal 8: No suggestions are offered at all in the middle of the list.

To reproduce in a clean Drupal install:

  • Install with Standard profile.
  • Go to node/add/article to add a new Article. Create one with several tags, such as cat, dog, fish, gerbil
  • Create a new article. Go to the Tags field. Type in a tag or two, then go back and attempt to edit one of the earlier tags.

Proposed resolution

Fix the auto-complete so that it detects where you are in the tag list, looks for suggestions matching the tag you are in, and puts the replacements in the right place when you're done choosing your selection.

Remaining tasks

Make a viable patch with tests.

User interface changes

The tag auto-complete will work properly when you're in the middle of a tag list.

API changes

Probably none.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

drumm’s picture

Project: Drupal.org infrastructure » Comment alter taxonomy
Version: » 6.x-1.x-dev
Component: Other » User interface
mr.baileys’s picture

Title: Issue tagging type-ahead wrong if in middle of list » Taxonomy autocomplete does not respect cursor position.
Project: Comment alter taxonomy » Drupal core
Version: 6.x-1.x-dev » 7.x-dev
Component: User interface » ajax system
FileSize
18.9 KB

Comment alter taxonomy just re-uses Taxonomy's forms and auto-complete logic, so this is not the correct queue. Seems that the same behavior occurs on standard D6 and D7 sites wherever a free-tagging vocabulary is used and without project_issue/comment_alter_taxonomy.

The taxonomy auto-complete seems to always auto-complete the last item in the list instead of respecting the cursor to see which term is being edited (see D7 screenshot below)

D7-taxonomy-autocomplete.jpg

jhodgdon’s picture

Priority: Normal » Major
Issue tags: +D7UX usability

Thanks for investigating. This looks like something we should fix in D7, and kind of a major usability issue? Even though it was also broken in D6, it still seems major to me.

rfay’s picture

subscribe.

Actually, autocomplete has not had enough attention over time and there are a number of issues open for it.

chx’s picture

Version: 7.x-dev » 8.x-dev
Priority: Major » Normal
stBorchert’s picture

Status: Active » Needs review
FileSize
5.11 KB

Here is a first working patch. If you edit a tag in the list its text will be used to search matching terms.
See https://img.skitch.com/20110604-fx6du4sy8pxrjq5mc57texpy4q.png

Status: Needs review » Needs work

The last submitted patch, autocomplete_caret_position-992020-6.patch, failed testing.

jhodgdon’s picture

Strange test glitch: failed to retrieve [autocomplete_caret_position-992020-6.patch] from [].

jhodgdon’s picture

Status: Needs work » Needs review
Issue tags: -D7UX usability

Status: Needs review » Needs work
Issue tags: +D7UX usability

The last submitted patch, autocomplete_caret_position-992020-6.patch, failed testing.

boombatower’s picture

Seems something on d.o didn't give PIFT the proper URL to send over to qa.d.o. Hmm.

Created #1178406: All tests failing: Relative patch file path used instead of absolute in patch testing.

rfay’s picture

Status: Needs work » Needs review
FileSize
5.11 KB

Just to see if it's some unexpected thing about file naming, here's the same patch with a different name. This is the same as #6.

Status: Needs review » Needs work

The last submitted patch, autocomplete_caret_position-992020_another_try.patch, failed testing.

stBorchert’s picture

Seems like PIFR didn't use the full path to the file ("//" in the beginning of path instead of a single "/").
https://img.skitch.com/20110604-ddu6xgxfgnfw5a4691t75dsh4q.png

stBorchert’s picture

Status: Needs work » Needs review

Next try with PIFR ...

Status: Needs review » Needs work

The last submitted patch, autocomplete_caret_position-992020_another_try.patch, failed testing.

stBorchert’s picture

Status: Needs work » Needs review
FileSize
5.26 KB

Next try with minor fix to prevent errors in test case.

chx’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests, +Needs backport to D7

Thanks for fixing this rather pesky issue. While the JS cant be tested easily surely you could emulate the requests JS will make and verify results.

stBorchert’s picture

Status: Needs work » Needs review
FileSize
7.73 KB

First try with one simple test case.

stBorchert’s picture

stBorchert’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests, +D7UX usability, +Needs backport to D7

The last submitted patch, autocomplete_caret_position-992020-19.patch, failed testing.

stBorchert’s picture

Status: Needs work » Needs review
FileSize
8.52 KB

Updated patch to latest head.

xjm’s picture

Rerolled for core/ with a slight doxygen correction.

jhodgdon’s picture

I read this patch over with regards to documentation.

I would like to suggest renaming the "caret position" variables and arguments to "cursor position". I've never heard of it being called a "caret"? This also applies to some in-code comments.

Also, this docblock is not up to standards at all:

 /**
  * Helper function for autocompletion
  */
-function taxonomy_autocomplete($field_name, $tags_typed = '') {
+function taxonomy_autocomplete($field_name, $tags_typed = '', $caret_position = 0) {

http://drupal.org/node/1354#functions

Other docblocks could use some @param/@return docs, but this one is particularly bad.

xjm’s picture

#25 I noticed that as well, but those lines aren't part of the patch change, so should be fixed in a separate issue. I am expecting taxonomy.module cleanup to take care of that.

I am also -1 on "caret".

xjm’s picture

Assigned: Unassigned » xjm

Eh I'll just rename the variable myself. :)

jhodgdon’s picture

Regarding the docblocks, several functions have arguments that are being changed in this patch. Their docblocks should be updated, and the new parameters should be documented. I realize that the former docblocks were garbage, but that is not (I think) a good reason not to document the functions now, especially since the new parameters may not be obvious what they are. They should be documented now.

xjm’s picture

The attached patch replaces the word "caret" with "cursor" and also polishes the inline comments a bit. I didn't touch the docblock for taxonomy_autocomplete() for the reasons stated in #26, but I made note of it in #1326644: Clean up API docs for taxonomy module.

The patch includes automated tests already. However, since this is JS functionality, we should have a few people test the functionality and report the results. Tagging as novice for manual review and testing.

xjm’s picture

Status: Needs review » Needs work

#28 Oh! Now I understand what you mean. Okay, fixing that. Sorry. :)

xjm’s picture

xjm’s picture

Status: Needs work » Needs review
FileSize
9.08 KB

Now that #1337124: Improve API documentation for taxonomy_autocomplete() is in, here's a reroll that adds documentation for the additional parameter.

xjm’s picture

Assigned: xjm » Unassigned
theamoeba’s picture

FileSize
9.76 KB
11.05 KB
12.91 KB
13.72 KB
12.56 KB

I have tested this patch on minimal-8.0-dev.

I created a taxonomy vocabulary called Testing.
Vocabulary

I then populated it it with three terms: Alpha, Beta, Gamma.
Terms

I created a content type called Page and added the term reference field as an autocomplete term widget (tagging).
Term Reference Field

Before implementing the patch in #32 I could replicated this issue.
After implementing the patch and clearing the cache I saw the following behavior: the patch fixes the issue respecting the cursor position but when selecting a suggested term it appends it to the end which is confusing to the user.

Auto Suggest
Appending to the end

xjm’s picture

Status: Needs review » Needs work

Thanks @theamoeba. That's a perfect test writeup. :)

I think we should change the function so it also orders the terms as expected after autocomplete. As @theamoeba pointed out in IRC, it becomes a usability issue.

xjm’s picture

From IRC:

davereid: xjm: Hrm, adding cursor position as an URL path seems odd. That should probably be a query string?

See also:
http://docs.jquery.com/UI/Autocomplete
http://jqueryui.com/demos/autocomplete/
Per Dave Reid there's an issue to replace our autocomplete with that in D8.

muka’s picture

Assigned: Unassigned » muka
FileSize
3.2 KB
7.09 KB
3.45 KB
6.94 KB

Hi,
here a revision of the patch #32 by xjm. It miss the autocomplete tests in taxonomy.test as I didn't found the appropriate code.



xjm’s picture

Setting NR for the bot. Thanks @muka!

xjm’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, autocomplete_cursor-992020-34.patch, failed testing.

muka’s picture

Status: Needs work » Needs review
FileSize
8.68 KB

Reviewed to add tests too

Status: Needs review » Needs work

The last submitted patch, autocomplete_cursor-992020-35.patch, failed testing.

muka’s picture

Status: Needs work » Needs review
FileSize
9.08 KB

Rerolled.

Status: Needs review » Needs work

The last submitted patch, autocomplete_cursor-992020-43.patch, failed testing.

dags’s picture

Assigned: muka » dags
dags’s picture

Status: Needs work » Needs review
FileSize
9.07 KB

Reroll.

Status: Needs review » Needs work

The last submitted patch, autocomplete_cursor-992020-46.patch, failed testing.

dags’s picture

Assigned: dags » Unassigned
Status: Needs work » Needs review
FileSize
4.6 KB
9.3 KB

Moving test into subclass to reduce number of fails. I'm also taking this off of myself for someone else to work on fixing the test failures.

Status: Needs review » Needs work

The last submitted patch, autocomplete_cursor-992020-48.patch, failed testing.

tim.plunkett’s picture

+++ b/core/modules/taxonomy/taxonomy.pages.incundefined
@@ -122,12 +121,28 @@ function taxonomy_autocomplete($field_name, $tags_typed = '') {
+  $position_last = -1;
+  foreach ($tag_positions as $position) {
+    if ($cursor_position >= $position_last && $cursor_position < $position) {
+      // Tag found on cursor position.
+      $tag_current = $tags_typed_array[$position_last];

This will always fail the first time around, since -1 is never valid.

+++ b/core/modules/taxonomy/taxonomy.pages.incundefined
@@ -122,12 +121,28 @@ function taxonomy_autocomplete($field_name, $tags_typed = '') {
-  if ($tag_last != '') {
+  if ($tag_current != '') {

With this change, $term_matches can now be empty, whereas before it wasn't.

bas.hr’s picture

Should we postpone this until #675446: Use jQuery UI Autocomplete is resolved?

nod_’s picture

Status: Needs work » Postponed

Yep, that would make sense.

jhodgdon’s picture

Status: Postponed » Needs work

It might make sense for Drupal 8.x, but it doesn't make sense for Drupal 7.x, where this is a long-standing and fairly annoying bug that will need to be fixed in the existing code. Can we consider not postponing it after all?

nod_’s picture

Oh right, D7 slipped out of my mind. Sorry about that.

droplet’s picture

the backend parser is borken as well. It may affect testbot result. #1329742: Autocomplete with tagging silently discards invalid input

tkoleary’s picture

Issue summary: View changes

Please follow progress on: #2346973: Improve usability, accessibility, and scalability of long select lists

Changing to Select2 may render this issue obsolete

heddn’s picture

Issue summary: View changes
Issue tags: +Needs issue summary update

Let's triage this a little more and see if

  1. this is an issue on D8. If it is, fix there.
  2. Then this will need to be backported to D7.
jhodgdon’s picture

Issue summary: View changes

I just updated the issue summary with clear steps to reproduce.

It is in fact still an issue in Drupal 8, where the auto-complete does not work at all in the middle of the list.

jhodgdon’s picture

tkoleary’s picture

Status: Needs work » Closed (cannot reproduce)

As of beta 10 I can no longer reproduce this.

Maybe it was solved by jquery update.

jhodgdon’s picture

Version: 8.0.x-dev » 7.x-dev
Status: Closed (cannot reproduce) » Needs work

In that case, we need to move it down to D7, where it is still a bug (which affects drupal.org among other things).

jhodgdon’s picture

Version: 7.x-dev » 8.0.x-dev

Actually, I think it is still an issue in Drupal 8. If you try to edit a tag in the middle of the taxonomy list, you get no suggestions at all. That is what is in the issue summary. Seems to behave the same now in 8.0.x

tkoleary’s picture

OK, I see now. I misunderstood the summary.

This issue would be solved in 8 by using Select2 if that issue lands #2346973: Improve usability, accessibility, and scalability of long select lists, which it could even in 8.1 since it does not impact backwards compatibility AFAICT.

IMO that's where we should put the effort and not waste time with a half-way fix to a problem for which there is a simple work around (delete the tag and start typing again at the end of the list).

andypost’s picture

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

jhodgdon’s picture

Status: Needs work » Closed (duplicate)

I attempted a while back to close #2186643: Autocomplete always searches the last tag as a duplicate of this issue. But at least one person there wanted to close this one instead. OK. Anyone on this issue that wants patch credit should put their patch on the other issue, which is newer but whatever.