Make WordPress Core

Opened 8 years ago

Closed 4 days ago

#21258 closed enhancement (worksforme)

Autosuggest for tags suggests tag already chosen

Reported by: roytanck Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Editor Keywords: has-patch needs-testing
Focuses: javascript, administration Cc:


When entering tags in the meta box on a post (or page) edit screen in admin, the AJAX autosuggest will suggest tags that have already been added to the post (i.e. shown below the input field).

Steps to reproduce:

  1. Go to the post edit screen.
  2. Add a tag (example: "Apple") to the current post.
  3. Type "App" in the tag entry field and wait for autosuggest to come up.
  4. "Apple" is listed in the suggestions dropdown.

I've investigated this a little, and I don't think there's a really easy patch for this (mostly because of how suggest.js works). However, it would imho be very elegant to fix this. Perhaps autocomplete.js can be of service here (see issue #12399)?

Attachments (3)

21258.diff (1.3 KB) - added by AugusGils 6 years ago.
21258.2.diff (1.5 KB) - added by AugusGils 6 years ago.
21258.3.diff (1.3 KB) - added by luistinygod 3 years ago.

Download all attachments as: .zip

Change History (11)

#1 @iseulde
7 years ago

  • Component changed from General to Editor

6 years ago

#2 @AugusGils
6 years ago

  • Keywords needs-testing has-patch added

I added the already added tags to the ajax call, and filter them out of the results array.
Here it works perfect on an 4.0 trunk.

6 years ago

#3 @AugusGils
6 years ago

I discoverd a bug with the items being cached after getting the ajax call.
I now deleted this cache rule, but don't know how much needed this was.

But in the end it would cause to fail my solution if you typed the beginning of a word and pressed enter (added the tag to the list), and then you enter the beginning of this tag again.

To reproduce the problem i had before my last diff:
Add tag: Apple
Begin typing: App
Add this tag with enter without saving the post
Then begin typing: App

With the cache on you again see Apple, now it's solved.

#4 @iseulde
6 years ago

  • Focuses javascript administration added
  • Keywords needs-patch added; needs-testing has-patch removed

Not sure if removing the cache is a good idea. Maybe better to filter in JS? Patching suggest.js is also not a good idea.

This ticket was mentioned in Slack in #core-editor by afercia. View the logs.

5 years ago

#6 @luistinygod
3 years ago

It seems previous patch based on suggest.js doesn't apply anymore. The tags suggest functionality moved to /wp-admin/js/tags-suggest.js file.

I'm preparing a patch.

3 years ago

#7 @luistinygod
3 years ago

  • Keywords has-patch needs-testing added; needs-patch removed

I discussed the fix with @adamsilverstein during WCEU contributor day.

Our first approach was to check if the added tags were already available as an object at wp but we couldn't find it.

As it is just a small fix in a very specific context, I opted to just check the DOM each time we need to filter the set of terms we receive from the server against the ones already added to the post, instead of going to a more pretty solution of having the added tags available as an object, which would need much more logic to maintain it in sync with the DOM (maybe at /wp-admin/js/tags-box.js).

#8 @noisysocks
4 days ago

  • Milestone Awaiting Review deleted
  • Resolution set to worksforme
  • Status changed from new to closed

Closing this out as the requested functionality exists in the block editor.

Note: See TracTickets for help on using tickets.