Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Limit number of tags returned in Ajax calls #13277

Closed
wants to merge 3 commits into from

Conversation

chrisdavenport
Copy link
Contributor

Pull Request for Issue #8074 and a replacement for PR #9155.

Summary of Changes

Finally got some time to look at this again. Although it's relatively straightforward to limit the number of tags initially shown in the drop-down (which was a problem for sites with thousands of tags), the list needs to be updated as tags are selected.

The problem is that if you select one or more tags from the list, then deselect them again (without clicking Save), the drop-down list is dramatically shortened to just those tags that have been added or removed since the page was loaded. The only way to load and select further tags is to start entering characters so that the search function kicks in.

With this PR, whenever a tag is selected an Ajax call is made so that tags are continually added to the drop-down list to replenish it.

In the process of writing this code I also made the JHelperTags::searchTags method a little smarter so that a considerable amount of duplicated code has been removed from JFormFieldTag::getOptions.

Testing Instructions

  • In Components -> Tags -> Options, set Maximum Items to something reasonably small, say 5.
  • Make sure you have more than that number of tags already created.
  • Edit an article, or some other content item with a tags field.
  • In the drop-down, notice that there are exactly 5 un-selected tags listed.
  • Select a tag from the list. In the drop-down, notice that an extra tag has been added to the list to maintain exactly 5 un-selected tags.
  • Deselect a tag. Notice that the drop-down now has 6 un-selected tags (we only add to the list, never remove from it).
  • Also check that it works as expected with UTF-8 tags.
  • Make sure I haven't broken anything else in the tags implementation.

Documentation Changes Required

None.

// Tag deselected so remove it from the internal list.
if (params.hasOwnProperty('deselected'))
{
var index = tagList.indexOf(parseInt(params.deselected));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@chrisdavenport indexOf is not compatible with IE8: http://stackoverflow.com/questions/3629183/why-doesnt-indexof-work-on-an-array-ie8
Use the polyfill from the link

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. I'm not a JS programmer, so I wasn't aware of that.

@ghost
Copy link

ghost commented Jan 5, 2017

I have tested this item 🔴 unsuccessfully on 5adfe42

Set maximum Items on 5, having 6 Tags. In "Article > Tags" Dropdown is empty.


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/13277.

@chrisdavenport
Copy link
Contributor Author

@franz-wohlkoenig Thanks for testing. Was the dropdown empty before you applied the PR?

Can you look in developer tools and see if the Ajax is throwing any errors? What version of Joomla did you test with? What database are you using? Any errors logged?

@ghost
Copy link

ghost commented Jan 5, 2017

Was the dropdown empty before you applied the PR?

  • Dropdown was not empty, all 6 Tags are shown

Can you look in developer tools and see if the Ajax is throwing any errors?

  • Where to look: "Console > JS", "Network"?

What version of Joomla did you test with?

  • 3.7.0-alpha2, Joomla! Nightly Builds

What database are you using?

  • MySQLi 5.5.53-0+deb7u1, PHP 7.0.4

Any errors logged?

  • Please write which Source you want to know

@webmiep
Copy link

webmiep commented Mar 31, 2017

I have tested this item 🔴 unsuccessfully on 5adfe42

Hello,
I have tested this.
Before appliing the PR I had 9 tags and in the dropdown all were shown.
After appliing I could not enter the article list becuase of this error:
Fatal error: Class 'JFormAbstractlist' not found in /home/eabbcbdv/public_html/nl/joomla8/libraries/cms/form/field/tag.php on line 20
I am sorry


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/13277.

@webmiep
Copy link

webmiep commented Mar 31, 2017

Hello,
It looks like my comment was not published.
Before adding the PR There were 9 tags in the component. By editting an article in the tags dropdown were all 9 in this list.
After adding the PR article manager could not be opened becaus of this error:
Fatal error: Class 'JFormAbstractlist' not found in /home/eabbcbdv/public_html/nl/mydomain/libraries/cms/form/field/tag.php on line 20

I am sorry


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/13277.

@brianteeman
Copy link
Contributor

I am closing this as it has not been successfully tested and there has been no comment from the OP

It can always be re-opened if fixed

@brianteeman brianteeman closed this Jan 4, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants