WordPress.org

Make WordPress Core

Opened 5 years ago

Last modified 5 months ago

#21258 new enhancement

Autosuggest for tags suggests tag already chosen

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

Description

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 3 years ago.
21258.2.diff (1.5 KB) - added by AugusGils 3 years ago.
21258.3.diff (1.3 KB) - added by luistinygod 5 months ago.

Download all attachments as: .zip

Change History (10)

#1 @iseulde
4 years ago

  • Component changed from General to Editor

@AugusGils
3 years ago

#2 @AugusGils
3 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.

@AugusGils
3 years ago

#3 @AugusGils
3 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
3 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.


2 years ago

#6 @luistinygod
5 months 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.

@luistinygod
5 months ago

#7 @luistinygod
5 months 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).

Note: See TracTickets for help on using tickets.