0

I have two views exposed filters,one dropdown field and a checkbox. I want,when the checkbox is checked the dropdown field to dissappear.When I uncheck the checkbox I want the dropdown field to appear again.

First I tried Views dependent filter,however it doesn't play well with Search api views.

Secondly I tried with javascript.I wrote this code and added it to the .js file of my theme.However it doesn't also work.How can I do this?

(function ($) {
  Drupal.behaviors.cdgi = {
    attach: function(context) {

      var $('#edit-field-level-of-telecommuting-1').prop('checked') = true;
      if ($('#edit-field-level-of-telecommuting-1').prop('checked') === true) {
        $('#edit-field-job-region-parents-all').hide();
      } else {
        $('#edit-field-job-region-parents-all').show();
      }
    }
  }
}(jQuery));`

2 Answers 2

1

There is a slight change in the code.May be this can help you.

(function ($) {
  Drupal.behaviors.cdgi = {
    attach: function(context) {
     $(function () {
      $('#edit-field-level-of-telecommuting-1').click(function() {
        if ($(this).prop("checked")) {
          $('#edit-field-job-region-parents-all').hide();
        } else {
          $('#edit-field-job-region-parents-all').show();
        }
      });
     });
    }
  }
}(jQuery));`

check more info how to include js file

4
  • Thanks for the reply,I tried this but still no luck.I have added this on the .js file of my theme,shall I add something else to the theme?
    – Dion
    Mar 10, 2015 at 18:33
  • i have edited the code.if you added the file correctly, i think it will work. try it and if not work let me know how did you add the file?
    – bisw
    Mar 10, 2015 at 18:55
  • I have pasted your code to the end of the cloudy.js file(the js file of my theme).I tried it,cleared caches but still no luck.Shall I do something more?thanks
    – Dion
    Mar 10, 2015 at 19:51
  • it is working fine in my case. Please be sure the file is calling in the page
    – bisw
    Mar 10, 2015 at 20:14
0

I finally found the solution to my problem using this code:

$('your selects class or id').change(function(){    
if($(this).val() == "publish_on"){
    $('.secret').fadeIn();
}
else{
    $('.secret').hide();
}

});

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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