Monday, January 2, 2023

remove Tid or Nid from Exposed filter of views Drupal9

 This is small code for remove Tid or Nid from Exposed filter of views Drupal9.

you need to add code into your custom javascript


(function($, Drupal, drupalSettings){

  'use strict';


   Drupal.behaviors.my_module = {

     attach: function(context) {


    // Remove TID's onload.

    Drupal.my_module.remove_tid();


    // Remove TID's onchange.

    jQuery('body').find('#your form ID').find('.form-autocomplete').on('autocompleteclose', function() {

      Drupal.my_module.remove_tid();

    });

                jQuery('body').find( '# your form id').find('.form-autocomplete').on('autocompleteclose', function() {

      Drupal.my_module.remove_tid();

    });


  }

  };


  Drupal.my_module = {

    remove_tid: function () {

      let field_autocomplete = jQuery('body').find('.form-autocomplete');

     // let autocomplete_tid_stripped = field_autocomplete.val().split(' ')[0];

//      console.log(autocomplete_tid_stripped);

                field_autocomplete.val(field_autocomplete.val().replace(/\(\d+\)/i, ""));

    },

  };


  })(jQuery, Drupal, drupalSettings);



No comments: