2

I want to use Showon in a nested XML file and I want to reference the original XML file's field name.

I read that this is not possible in Joomla! Subforms because if I were to create the same fieldname in the subform which one would it choose? (I personally would vote for the closest one i.e. the one in the currect xml).

Anyway this is not possible is there another way?

Here are my files

Main Subform

<?xml version="1.0" encoding="UTF-8"?>
<form>
  <fieldset name="image-fieldset">
    <field name="media_manager_or_url"
          type="list"
          label="MOD_KOU_BACKGROUND_IMAGE_WITH_TEXT_MEDIA_MANAGER_OR_URL_LABEL"
          description="MOD_KOU_BACKGROUND_IMAGE_WITH_TEXT_MEDIA_MANAGER_OR_URL_DESCRIPTION"
          default="0"
          >
            <option value="0">MOD_KOU_BACKGROUND_IMAGE_WITH_TEXT_MEDIA_MANAGER</option>
            <option value="1">URL</option>
    </field>
    <field name="images-subform"
            label= "MOD_KOU_BACKGROUND_IMAGE_WITH_IMAGES_SUBFORM_LABEL"             
            description= "MOD_KOU_BACKGROUND_IMAGE_WITH_IMAGES_SUBFORM_DESCRIPTION"
            type= "subform"
            min= "1"
            max= "1000"
            required= "true"
            formsource= "/modules/mod_kou_background_image_with_text/xml/media_manager_or_url.xml"
            multiple= "true"
            buttons= "add,remove"
            layout="joomla.form.field.subform.repeatable"
            groupByFieldset="false"
  />        
  </fieldset>
</form>

Secondary Subform

<?xml version="1.0" encoding="UTF-8"?>
<form>
  <fieldset name="media-manager-or-url-fieldset">
    <field name="image"
          type="media"
          label="MOD_KOU_BACKGROUND_IMAGE_WITH_TEXT_IMAGE_LABEL"
          description="MOD_KOU_BACKGROUND_IMAGE_WITH_TEXT_IMAGE_DESCRIPTION"
          showon="media_manager_or_url:0"
          />       
    <field  name="url"
            type="url"
            label="MOD_KOU_BACKGROUND_IMAGE_WITH_TEXT_URL_LABEL"
            description="MOD_KOU_BACKGROUND_IMAGE_WITH_TEXT_URL_DESCRIPTION"
            showon="media_manager_or_url:1"            
    />
    <field  name="real-size"
            type="text"
            label="MOD_KOU_BACKGROUND_IMAGE_WITH_TEXT_REAL_SIZE_LABEL"
            description="MOD_KOU_BACKGROUND_IMAGE_WITH_TEXT_REAL_SIZE_DESCRIPTION"            
    />
    <field  name="size"
            type="text"
            label="MOD_KOU_BACKGROUND_IMAGE_WITH_TEXT_SIZE_LABEL"
            description="MOD_KOU_BACKGROUND_IMAGE_WITH_TEXT_SIZE_DESCRIPTION"            
    />               
  </fieldset>
</form>
3

By breaking up the files into multiple subforms you can use showon. Here is what I ended up with.

Main Subform

<?xml version="1.0" encoding="UTF-8"?>
<form>
  <fieldset name="image-fieldset">
    <field name="media_manager_or_url"
          type="list"
          label="MOD_KOU_BACKGROUND_IMAGE_WITH_TEXT_MEDIA_MANAGER_OR_URL_LABEL"
          description="MOD_KOU_BACKGROUND_IMAGE_WITH_TEXT_MEDIA_MANAGER_OR_URL_DESCRIPTION"
          default="0"
          >
            <option value="0">MOD_KOU_BACKGROUND_IMAGE_WITH_TEXT_MEDIA_MANAGER</option>
            <option value="1">URL</option>
    </field>
    <field name="media-manager-images-subform"
            label= "MOD_KOU_BACKGROUND_IMAGE_WITH_IMAGES_SUBFORM_LABEL"             
            description= "MOD_KOU_BACKGROUND_IMAGE_WITH_IMAGES_SUBFORM_DESCRIPTION"
            type= "subform"
            min= "1"
            max= "1000"
            required= "true"
            formsource= "/modules/mod_kou_background_image_with_text/xml/media_manager_images_subform.xml"
            multiple= "true"
            buttons= "add,remove"
            layout="joomla.form.field.subform.repeatable"
            groupByFieldset="false"            
  />       
    <field name="url-images-subform"
            label= "MOD_KOU_BACKGROUND_IMAGE_WITH_IMAGES_SUBFORM_LABEL"             
            description= "MOD_KOU_BACKGROUND_IMAGE_WITH_IMAGES_SUBFORM_DESCRIPTION"
            type= "subform"
            min= "1"
            max= "1000"
            required= "true"
            formsource= "/modules/mod_kou_background_image_with_text/xml/url_images_subform.xml"
            multiple= "true"
            buttons= "add,remove"
            layout="joomla.form.field.subform.repeatable"
            groupByFieldset="false"
            showon="media_manager_or_url:1"
  />          
  </fieldset>
</form>

Secondary Subform

<?xml version="1.0" encoding="UTF-8"?>
<form>
  <fieldset name="media-manager-or-url-fieldset">
    <field name="image"
          type="media"
          label="MOD_KOU_BACKGROUND_IMAGE_WITH_TEXT_IMAGE_LABEL"
          description="MOD_KOU_BACKGROUND_IMAGE_WITH_TEXT_IMAGE_DESCRIPTION"
          showon="media_manager_or_url:0"
          />       
    </field>
    <field  name="url"
            type="url"
            label="MOD_KOU_BACKGROUND_IMAGE_WITH_TEXT_URL_LABEL"
            description="MOD_KOU_BACKGROUND_IMAGE_WITH_TEXT_URL_DESCRIPTION"
            showon="media_manager_or_url:1"            
    />
    <field  name="real-size"
            type="text"
            label="MOD_KOU_BACKGROUND_IMAGE_WITH_TEXT_REAL_SIZE_LABEL"
            description="MOD_KOU_BACKGROUND_IMAGE_WITH_TEXT_REAL_SIZE_DESCRIPTION"            
    />
    <field  name="size"
            type="text"
            label="MOD_KOU_BACKGROUND_IMAGE_WITH_TEXT_SIZE_LABEL"
            description="MOD_KOU_BACKGROUND_IMAGE_WITH_TEXT_SIZE_DESCRIPTION"            
    />               
  </fieldset>
</form>

By breaking the form into subform parts which was not my first logic I was able to acheive this result without using any JavaScript.

The slight downside was that instead of using 1 subform with 4 elements, I had to use two with 3 elements. For me as they were identical this copy and paste job was easy enough and it solved my problem using only Joomla! core.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.