Update a component's select field using ajax after another field value has been selected

by mickmackusa   Last Updated March 13, 2019 05:10 AM - source

I would like to populate the "Owner" select option list by SELECTing the owner column from the #__gscrm_accounts table WHERE the gscrm_account_id (primary key) is the selected "Person or Business" value.

This ajax needs to be triggered by the onselect() event of <field name="account"> then populate <field name="owner">.

enter image description here

To be clear, I don't know if this is "fresh" or "modified" copy of SimpleCRM because I've never used SimpleCRM and this project was just thrown at me.

In components/com_gscrm/View/Notes/tmpl/form.form.xml, the "Person or Business" select field is generated from:

<field name="account" class="high28" labelclass="label_left" label_placement="top"
    <state key="code">[ITEM:CODE]</state>

The "Owner of this contact" field is generated by:

<field name="owner" emptylabel="1" class="high28" labelclass="label_left" label_placement="top" label="COM_GSCRM_NOTES_OWNER_LABEL"
    <state key="code">[ITEM:CODE]</state>               

I know that I will need to add a bit of complexity to the query that I actually require and it might not be a single "owner" value that I am returning, but my question is: How do I execute the ajax process using best practices and pre-existing classes/methods if possible?

I had a look at https://docs.joomla.org/J3.x:Developing_an_MVC_Component/Adding_AJAX but that isn't specifically dealing with <field> tags.

This looks close: How to change select list from another using AJAX in Joomla but I am not sure about the best placement of the files and I am not dealing with chozen elements.

Soren's answer indicates that I should be crafting a url like:


If so, where do I best park my getOwners() method?

Loading the options of a select form field via jQuery Ajax looks similar, but mostly yatta-yattas over the fundamental pieces that I require:

All of the posts have a fair bit of age on them and I expect to see a token used in this process.

Related Questions

Showon does not work in frontend

Updated March 28, 2016 08:04 AM

passing an array from view to controller to model

Updated March 11, 2018 17:10 PM

Field of type contact

Updated July 30, 2018 21:10 PM