8 years ago
Topic

Hello Communiy, 

I would like to ask you some help in Select Dynamic Cascade field. 

I am using this field(s) to select the category of articles. 

Basically I have two dynamic cascade fields: cat_level1 and cat_level2.

I Would like to realize the following conditions for cat_level2: 

  • if cat_level1 selected -> cat_level2 is visible;
  • if cat_level2 has no options -> cat_level2 is hidden;
  • if cat_level2 visible -> it shows Select an Option label.

I could realize the above with "Conditional States" if there is no "Select Label" defined for cat_level2 but in my application it should be used. I am using seb_one template with custom positions, so I can use JavaScripts, but unfortunatelly I am not a programmer. 

Any help would be appreciated!

Thank you!

István

Get a VIP membership
572 Posts
_jrmo
8 years ago
1
Level 1

Hi zrinyi,

Unfortunately I don't have a solution for this. I also have a project at the moment which needs this functionality. Hopefully someone out there in the community can assist us!

James

8 years ago
0
Level 2

Hi James,

I think in the end I found the solution:

(function($) {
	// hide second level if first level not selected
	if( !$('#cascade_level1').val() ) { 
		$("#cck1r_cascade_level2").hide();
	}
	$("#cascade_level2").on('change', function(){
		// hide second level if it hasn't got any options
		if ($("#cascade_level2 option[value!='']").length == 0) {
			$("#cck1r_cascade_level2").hide();
		} else {
		// show second level if it has option(s)
			$("#cck1r_cascade_level2").show();
		}
	});
})(jQuery);

For sure, there is better solution, but it is working for me.

Any other solutions are welcome.

Regards

István

Get a Book for SEBLOD