Allows Joomla custom fields — including those in subforms — to be displayed or hidden based on another custom field's value.

Joomla's custom fields is a very powerful feature. When used with custom template overrides you can create rich, custom layouts for your site which won't need redoing when you upgrade your Joomla version or change your template. This very site is an example of using custom fields like so.

One feature sorely missing from the core is the ability to have conditional display of custom fields. Let's use an example to best understand the problem.

Let's say that your client is an artist who wants to showcase their work on–line. They produce both physical paintings on canvas and digital art. The latter can be vector or bitmap. They want to list the dimensions of their work along with other information such as the title, the year it was made, and some commentary on what the art means to them.

Here's the catch. Physical paintings are sized in centimetres — they are European. Bitmaps are sized in pixels. Vectors have an aspect ration but not an intrinsic size per se. How do you reconcile these different needs?

Back in the olden days you'd just cop out and include the dimensions as text in the full text area of the article. However, this does not let you manage the dimensions easily. What if the artists adds 153 of their works and then decide they need the dimensions tagged with micro–data? You'd have to edit all 153 articles one by one. Oops, they gave you the wrong specification for the micro–data. Not a big problem, right? Well, here you go editing 153 articles one by one again. Hm, but they don't like the display. Can you adjust the font size here? Okay, another 153 articles to edit. You see where this is going...

Using custom fields you can make all these changes by changing one template override, once. It's substantially faster. Think about 5 minutes versus 5 to 8 hours kind of faster. it also narrows down the opportunity of a mistake to one place which can be easily edited. If only you could find how to ask for all the information using Custom Fields.

Since Joomla 3.7 you would probably come up with the following custom fields:

  • Medium (medium): List field with options canvas, bitmap, and vector
  • Canvas Width (canvas-width): Integer field
  • Canvas Height (canvas-height): Integer field
  • Bitmap Width (bitmap-width): Integer field
  • Bitmap Height (bitmap-height): Integer field
  • Vector Aspect Ratio (vector-aspect): Text field

This is ridiculous. You select the medium of the artwork, it doesn't make sense to list all five fields!

This is the problem we are addressing with this plugin. Joomla already has a solution for that in its XML forms: the showon attribute which allows developers to display fields conditionally. This plugin brings the showon attribute to custom fields as well by adding a Show On parameter.

In our example above you'd have the Show On parameter on the canvas fields to medium:canvas, on the bitmap fields to medium:bitmap and the Vector Aspect Ratio field to medium:vector. Now your artist client only sees the relevant information.

This is not something new; a plugin for that already existed and was written by JoomTools. It was, however, doing a bit too much and too little at the same time — issues which are addressed in this plugin.

The JoomTools plugin would not support Show On for custom fields contained in subform custom fields. That's because Joomla renamed these fields when displaying them in the subform. This is addressed by my plugin but the way to do that is incompatible with the way the other plugin is working, therefore I could not do a Pull Request to his repository and had to fork the entire plugin.

The other problem I had is that the JoomTools plugin would completely remove the fields not displayed because of their Show On preference. I still needed to have access to them — in some cases I could only determine the content type based on whether a field was defined for a content item. So, I removed this part. This of course means that this plugin will only make sense if you are displaying custom fields with template overrides — as opposed to using the default rendering of custom fields by Joomla before and after the content.