Question

Suppose my website sells cars and other methods of transportation. I have a content type called Product and it is categorised with a taxonomy, eg. Cars, Bicyces, Boats, Helicopters.

The Product content-type has some CCK fields to describe basic features of the product, such as horsepower, number_of_wheels, and top_speed.

I use views to override the taxonomy term page, and show some exposed filters so the user can narrow their choices.

My problem is, that some of my exposed filters aren't really applicable when viewing certain terms. For example if I'm viewing the Bicycles term, I don't want to be able to filter by horsepower! Or if I'm viewing Boats I don't want to be able to filter by number_of_wheels (because none of my boats have wheels).

So is there a way to hide an exposed filter for a field if no rows in the view contain data in that field?

Was it helpful?

Solution

Having just one content type "Products" although simple, will ultimately cause redundancies and problems, such as what your experiencing now. It's far better to add individual content types; cars, bikes, boats and set fields unique to them. That way you can create filters easily in views against the content type.

If you were to create the table in mysql would you have just one table Products? I hope not. ;-)

OTHER TIPS

If you're not able to branch your content types as Gary Green suggests, making separate views (with more granular control of view filters), you could perhaps you could use hook_form_alter to check the default value of the taxonomy field corresponding to your product type (bicycles, boats, etc.), and then remove fields by setting #access for those fields to FALSE.

If you're not comfortable with using hook_form_alter, you could also set these to display: none with jQuery (don't remove them, or the forms won't pass the security / integrity test upon submission). Unfortunately you can't do this with simple css because, at least in D6, CCK filter input elements don't have specific enough id's or classes to allow easy css manipulation.

This presupposes that you have separate views pages for each of the taxonomy-determined product types; your description sounds like this type of setup.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top