1

I have a form field which needs to be shown depending on value selected for another field. For example

<field name="field1" type="list" label="LABEL1" description="DESC1" filter="intval" size="1" default="0" class="form-control">
  <option value="0">Option 0</option>
  <option value="1">Option 1</option>
</field>
<field name="field2" showon="field1:1" type="list" label="LABEL2" description="DESC2" filter="intval" size="1" default="0" class="form-control">
  <option value="3">Option 3</option>
  <option value="4">Option 4</option>
</field>

In my above code, field2 will be shown only when field1 value is 1. This works fine from the front-end form. However the same form does not work in my admin component. Is there any special JavaScript file needs to be loaded for this to work?

  • Found what the issue is. I was using $this->form->getInput('field2'); but showon attribute working only if I render the field using $this->form->renderField('field2'); . Hope this helps someone facing the same issue. – Nagarjun Sep 20 '15 at 8:15
  • Please write this as a proper answer and accept it so other know it has been solved ;) – Lodder Sep 20 '15 at 11:45
7

Found what the issue is. I was using getInput function to show the field.

$this->form->getInput('field2'); 

but showon attribute working only if I render the field using renderField function

$this->form->renderField('field2'); 

Hope this helps someone facing the same issue

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.