Hi, i have a field collection with five fields inside, i need that when one field is checked another field is hidden. I want to use a drupal behavior to attach my event to every new field collection item generated at the press on the "add another item" button.

(function ($) {


     function vedi_se_nascondere(){
     
		if ($("#edit-field-istruzione-e-formazione-und-0-field-ancora-in-corso-istr-und").is(":checked"))
		{      //this is the div wrapper that i need to hide
			$("#field-istruzione-e-formazione-und-0-field-data-fine-formazione-add-more-wrapper").hide("fast");
		}
		else
		{
			$("#field-istruzione-e-formazione-und-0-field-data-fine-formazione-add-more-wrapper").show("fast");
		}

			}

  Drupal.behaviors.miotema = {
    attach: function(context) {
           //my boolean field
           $("#edit-field-istruzione-e-formazione-und-0-field-ancora-in-corso-istr-und").click(function(){

	     																							vedi_se_nascondere();
	     																							});
    
    }
  };

})(jQuery);

can you help me? thanks in advice

Comments

ninjacoderz’s picture

That is exactly what I need to! Have anyone here? Please help!

rafuel92’s picture

Hi, i solved it adding this js file to my omega subtheme, hope that this will solve your problem :)

(function ($) {


  function vedi_se_nascondere_istruzione(obj){
  
 // $(obj).parent().find('.field-name-field-data-fine-formazione')
			if ($(obj).find('input').is(":checked"))
			{      //this is the div wrapper that i need to hide
				 $(obj).parent().find('.field-name-field-data-fine-formazione').hide("fast");
			}
			else
			{
				 $(obj).parent().find('.field-name-field-data-fine-formazione').show("fast");
			}

		}
   
    function vedi_se_nascondere_esperienza(obj){
  
 // $(obj).parent().find('.field-name-field-data-fine-formazione')
			if ($(obj).find('input').is(":checked"))
			{      //this is the div wrapper that i need to hide
				 $(obj).parent().find('.field-name-field-data-fine-esperienza').hide("fast");
			}
			else
			{
				 $(obj).parent().find('.field-name-field-data-fine-esperienza').show("fast");
			}

		}




  Drupal.behaviors.miotema = {
    attach: function(context) {
           //my boolean field
           
           $(".field-name-field-ancora-in-corso-istr",context).click(function(){

	     																							vedi_se_nascondere_istruzione(this);
	     																							});
	     	$(".field-name-field-in-corso").click(function(){
		     					
		     					vedi_se_nascondere_esperienza(this);
		     					
	     						});
    
    }
  };

})(jQuery);
psvinith’s picture

is anyone knows , where it is exactly came from core, i mean which js