Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>As Carlos Granados said you have basically two options:</p> <ol> <li><p>Create a separate Symfony actions that takes a country as parameter and returns a list of associated regions in XML or JSON format. (You can use <code>Symfony\Component\HttpFoundation\JsonResponse</code>to send a JSON response, however, there is no corresponding <code>XmlResponse</code> class). Use <a href="http://jquery.com" rel="nofollow">jQuery</a> (or any other JS library or even plain Javascript) to send a request to the server whenever a user changes the currently selected item. In the callback (when you retrieved the response in the Javascript) you can update the region select box. You may find the documentation of <a href="http://api.jquery.com/jQuery.get/" rel="nofollow">jQuery Ajax</a> interesting.</p></li> <li><p>You store a list of all countries and its associated regions in your HTML code (you can use JSON or generate a native Javascript array) and whenever a user changes the value of the country select box you just have to replace the list of regions in the regions select box.</p></li> </ol> <p>The second method has a heavier load on the initial loading of the form since all countries and its associated regions must be loaded (from the database or a text file or wherever you store them) and rendered in a format that can be easily read by JS.</p> <p>The first method however must send a request every time a user selects another country. Additionally you have to implement another action.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload