0

I'm working on a custom Joomla module. I have a JForm that contains multiple custom dropdown lists based on JFormFieldList. The form should be submitted when a value is selected from one of the custom lists.

What is the best way to do this? It seems that I should add the following expression to select html tag: onchange="this.form.submit()

https://stackoverflow.com/questions/7231157/how-to-submit-form-on-change-of-dropdown-list

But as the html select tag is not directly generated by my code, I'm not sure how to do this the best.

Any hints are highly appreciated! Thanks!

  • 1
    Just to have this clearer: what is the purpose of submitting the form at every selection? I ask this since I answered this kind of questions earlier and it came out that it was not important to submit the form at every input, only the person who has asked the question have not understand before how jQuery ajax works on forms for example. So what’s the purpose here? Please give a bit more details about that. – Zollie Jan 23 at 18:45
  • There is a cascading relationship between list1 and list2, so the options in list2 will be narrowed down based on the selection in list1. In general I understand the concept of AJAX and partially reloading a page, but I have no experience in how this works for Joomla and PHP, so I wanted to implement a full page reload first quickly and maybe adding the ajax functionality later on when I have more time. If there is an easy and quick way to do this with AJAX that would be also perfect. – wanderlusted Jan 23 at 20:40
  • Thank you! Now it’s quite clear what you would like to have and why. Me or someone else here will be able to help you in this based on the above. – Zollie Jan 23 at 20:43
1

onchange attribute can be added to the fields in your XML form. E.g. this is used in filter forms:

<field
    name="access"
    type="accesslevel"
    label="JOPTION_FILTER_ACCESS"
    description="JOPTION_FILTER_ACCESS_DESC"
    onchange="this.form.submit();"
    >
    <option value="">JOPTION_SELECT_ACCESS</option>
</field>

If your component follows Joomla's standard MVC pattern, you can use controller's reload() method to reload the form.

onchange="Joomla.submitform('example.reload', this.form)"

Where example is the name of the controller.

  • Wow, this is really simple and works like a charm! Thanks a lot! BTW: I don't think I saw any mentioning of an "onchange" attribute in the standard form field types documentation or anywhere else. What is the best way to learn about options like this? – wanderlusted Jan 25 at 7:41

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.