3

in my view/tmpl/default.php, I want to get the Id of the input field report:

<div class="control-group">
    <div class="control-label"><?php echo $this->form->getLabel('report'); ?></div>
    <div class="controls"><?php echo $this->form->getInput('report'); ?></div>
</div>

I want to use the ID to perform a javascript function. Where can I get the ID?

<field name="report" type="foreignkey" class="inputbox"
        label="COM_SUBSCRIPTION_FORM_LBL_SUBSCRIPTIONS_REPORT"
        description="COM_SUBSCRIPTION_FORM_DESC_SUBSCRIPTIONS_REPORT" input_type="list" table="#__users" key_field="id" value_field="name"  required="true"  />
0

2 Answers 2

6

Joomla uses value of name attribute along with a prefix (prefix_valueOfnameAttribute) to generate Id of the field in case there is not id attribute provided.

If you add id attribute in your xml then this provided id is automatically gets added to the form field.

prefix mentioned above is the argument which you pass while getting Form instance.

2
  • I used the inspect element on my webpage, and found out that the input field has a prefix of 'jform'. The complete Id of the input report is 'jform_report'. I guess the jform_ is the prefix that you are mentioning. Thanks! Dec 4, 2014 at 9:02
  • yes, you understood correctly.
    – Nick
    Dec 4, 2014 at 9:07
3

If the input requires an ID you should place it in the .xml also, e.g:

<field name="report" type="foreignkey" class="inputbox"
       id="subscriptions-report"
       label="COM_SUBSCRIPTION_FORM_LBL_SUBSCRIPTIONS_REPORT"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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