CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Post-installation Setup and Configuration (Moderator: Dave Greenberg) »
  • Removing an option from Select2 Actions list
Pages: [1]

Author Topic: Removing an option from Select2 Actions list  (Read 5652 times)

allenthehusband

  • I’m new here
  • *
  • Posts: 27
  • Karma: 2
  • CiviCRM version: 4.5
  • CMS version: Drupal 7
  • PHP version: 5.3
Removing an option from Select2 Actions list
October 31, 2014, 04:05:44 pm
In 4.4.x versions I had the below code in "custom template folder"/CRM/Contact/Form/Search/Advanced.extra.tpl to remove an option from the Actions list on Advanced Search results.  It did the job well.

Code: [Select]
// hides Delete Permanently option from advanced search results screen
cj('#task option[value=24]').remove();

We recently upgraded to 4.5.2.  With the move to 4.5.x came the move to select2 lists (which are awesome).  I'm just still learning how they work.  I've spent the afternoon learning about the various functions of select2, but haven't yet nailed down how exactly to remove an option from the list.

How do I remove an option from a select2 list like the above code did in 4.4.x?  Thanks for the help!

Coleman Watts

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 2346
  • Karma: 183
  • CiviCRM version: The Bleeding Edge
  • CMS version: Various
Re: Removing an option from Select2 Actions list
October 31, 2014, 04:18:44 pm
That code should still work - select2 automatically syncs with the underlying <select> element and if you manipulate it, select2 will re-render itself appropriately.
When I pasted your code into my console, the "Delete Permanently" option indeed went away.
Try asking your question on the new CiviCRM help site.

allenthehusband

  • I’m new here
  • *
  • Posts: 27
  • Karma: 2
  • CiviCRM version: 4.5
  • CMS version: Drupal 7
  • PHP version: 5.3
Re: Removing an option from Select2 Actions list
November 01, 2014, 09:45:17 am
Coleman,

Thanks for setting me straight and explaining the underlying operation of the Select2 lists.  I'm not sure what happened.  I reloaded the extra.tpl file and it worked. Thanks again (and for the quick reply too!).

Coleman Watts

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 2346
  • Karma: 183
  • CiviCRM version: The Bleeding Edge
  • CMS version: Various
Re: Removing an option from Select2 Actions list
November 01, 2014, 12:15:56 pm
Also FYI you could update your code for the new js standards in 4.5.
  • The cj variable (which stores our copy of jQuery) has been renamed to CRM.$ to give us one less global variable and more consistency with other libraries (e.g. CRM._ is our copy of underscore).
  • Accessing it directly is discouraged, we suggest you use a closure.
So your new code would look like this:
Code: [Select]
CRM.$(function($) {
  $('#task option[value=24]').remove();
});

We will maintain backward support for the cj variable for another version at least, but here's a heads up.
Try asking your question on the new CiviCRM help site.

allenthehusband

  • I’m new here
  • *
  • Posts: 27
  • Karma: 2
  • CiviCRM version: 4.5
  • CMS version: Drupal 7
  • PHP version: 5.3
Re: Removing an option from Select2 Actions list
November 01, 2014, 01:22:23 pm
Thank you for the heads up, Coleman.  I'll start implementing the new js standards.

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Post-installation Setup and Configuration (Moderator: Dave Greenberg) »
  • Removing an option from Select2 Actions list

This forum was archived on 2017-11-26.