Joomla Form Field items have a useful attribute "showon" which allows you to automatically only display the field if certain other field conditions you specify are met. This can greatly reduce clutter in the form as irrelevant elements remain hidden until they need to be set.

For a simple example you might have enable categories for a component, and also want to set a default category if categories are enabled.


xbmaps catenable

xbmaps catdef

This is all well and good but there is a quirk. showon only works for fields in the same fieldset. Fieldsets are used to group fields together, largely to make it easier to display them all with a single line of code (assuming you are happy with the default layout). But there may be occasions where you want to show a field, or fields, dependent of the setting of a field in another fieldset on the same form.

Apparently the javascript which Joomla uses to evaluate the showon condition and hide or display the field is capable of working across fieldsets, but there was a problem implementing the php side logic in the FormField class, so it was never used. In response to my question on it was suggested that an answer was to write a custom field type that included a revised renderField() function. 

The problem with that is you'd have to write fresh field types for each type of field you wanted to use - which is a bit of an overhead.

My preferred simpler solution is to include an extra hidden field in the target fieldset which replicates the value of the field you want to test. Use javascript with the source field onchange event to update the hidden field and fire that field's changed event thus triggering any other fields that are dependent on the value to update their status.


    <fieldset name="default">
<!-- other fields as required -->
        <field name="marker_type" type="list"
  	    onchange="var targ=document.getElementById('jform_params_hidmarker_type');targ.value=value;targ.dispatchEvent(new Event('change'));"
	    <option value="0">Default</option>
	    <option value="1">Image</option>
	    <option value="2">Awesome</option>
<fields name="params">
    <fieldset name="params" label="JGLOBAL_FIELDSET_DISPLAY_OPTIONS" >
	<field name="hidmarker_type" type="hidden"
	<field name="marker_image" type="imagelist"
	    directory = ""
	    hide_none="true" hide_default="true"
 <!-- etc -->