How to Alphabetize the Tag field Suggestions Dropdown List | Community
Skip to main content
Nandheswara
Level 4
March 22, 2024
Solved

How to Alphabetize the Tag field Suggestions Dropdown List

  • March 22, 2024
  • 1 reply
  • 860 views

Hi all,

 

I need to alphabetize the Tag field Suggestions Dropdown List, I tried with the approach of overlaying the suggestion.jsp file Which is in /libs/cq/gui/components/coral/common/form/tagfield/suggestion/suggestion.jsp

but the dropdown list was alphabetize order upto 10 results and next 10 results re-alphabetize again due to the results came under different responses, where each response holds only 10 results.

As I observed this line from

/libs/cq/gui/components/coral/common/form/tagfield/render.jsp

Where the offset.limit is causing the 10 results per response

final String suggestionsrc="/mnt/overlay/cq/gui/content/coral/common/form/tagfield/suggestion{.offset,limit}.html?root=" + Text.escape(tagRootPath) + "{&query}";

So is there any default way get the entire result as a single response alphabetize, kindly give some suggestions on this please.

 

Thanks

Nandheswara

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by EstebanBustamante

Hi, 


The reason for requesting results in a subset, of course, is to avoid performance issues. Bringing everything at once just for filtering may be risky. I would recommend sorting this using JavaScript. Once the dialog/page loads, you can trigger a JS hook to rearrange the HTML elements that are part of the dropdown and sort them out however you need.

 

Something like this:

// Get the dropdown element var dropdown = document.getElementById('myDropdown'); // Get all the options within the dropdown var options = Array.from(dropdown.options); // Sort the options alphabetically based on their text content options.sort(function(a, b) { return a.text.localeCompare(b.text); }); // Remove all existing options from the dropdown dropdown.innerHTML = ''; // Add sorted options back to the dropdown options.forEach(function(option) { dropdown.add(option); });

 

Hope this helps!

 

1 reply

EstebanBustamante
Community Advisor and Adobe Champion
EstebanBustamanteCommunity Advisor and Adobe ChampionAccepted solution
Community Advisor and Adobe Champion
March 22, 2024

Hi, 


The reason for requesting results in a subset, of course, is to avoid performance issues. Bringing everything at once just for filtering may be risky. I would recommend sorting this using JavaScript. Once the dialog/page loads, you can trigger a JS hook to rearrange the HTML elements that are part of the dropdown and sort them out however you need.

 

Something like this:

// Get the dropdown element var dropdown = document.getElementById('myDropdown'); // Get all the options within the dropdown var options = Array.from(dropdown.options); // Sort the options alphabetically based on their text content options.sort(function(a, b) { return a.text.localeCompare(b.text); }); // Remove all existing options from the dropdown dropdown.innerHTML = ''; // Add sorted options back to the dropdown options.forEach(function(option) { dropdown.add(option); });

 

Hope this helps!

 

Esteban Bustamante