I created a view from taxonomy terms of different country names. I added an exposed filter to allow the user to enter the country, but when the user selects the country, it automatically adds the taxonomy ID after the name.

I've tried various things, from hooks to jQuery, I can't seem to figure out how to remove the TID. Please advise.

enter image description here


One solution can be custom javascript to remove the number from the result: like

(function($, Drupal, drupalSettings){
'use strict';

 Drupal.behaviors.my_module = {
   attach: function(context) {

  // Remove TID's onload.

  // Remove TID's onchange.
  jQuery('body').find('#YOUR_FILTER_EXPOSED_ID').find('.form-autocomplete').on('autocompleteclose', function() {

Drupal.my_module = {
  remove_tid: function () {
    let field_autocomplete = jQuery('body').find('.form-autocomplete');
    let autocomplete_tid_stripped = field_autocomplete.val().split(' ')[0];

})(jQuery, Drupal, drupalSettings);

Another solution could be using views_autocomplete_filter module, add a relation to your taxonomy term and instead of entity filter and a filter on terms name, so there will not id there. a little slower but works.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.