I am trying to test a form with symfony with a code copied from the internet. It is about two selects, province and city, in which the values of City depend on what is selected in the Province, but when I load the page it marks the following error:
An exception has been thrown during the rendering of a template ("Unable to generate a URL for the named route" province_ajax_call "as such a route does not exist.") in NoxLogicDemoBundle: Default: index.html.twig at line 38.
The code is as follows:
{% block title %}Contact{% endblock%}
{% block body %}
<header>
<h1>Crear evento</h1>
</header>
<p>Want to contact symblog?</p>
<form action="{{ path('NoxLogicDemoBundle_formu') }}" method="post" {{ form_enctype(form) }} class="evento">
{{ form_errors(form) }}
{{ form_row(form.name) }}
{{ form_row(form.province) }}
{{ form_row(form.city) }}
{{ form_rest(form) }}
</form>
{% block javascripts %}
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
<script src="http://code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
<script type="text/javascript">
$(document).ready(function ()
{
$('#account_type_province').change(function()
{
var val = $(this).val();
$.ajax(
{
type: "POST",
url: "{{ url('province_ajax_call') }}?province_id=" + val,
success: function(data)
{
// Remove current options
$('#account_type_city').html('');
$.each(data, function(k, v) {
$('#account_type_city').append('<option value="' + v + '">' + k + '</option>');
});
}
});
return false;
});
});
</script>
{% endblock %}
{% endblock %}
All the code I am using is copied from a page that explains how to make dependent selects in symfony: link
I understand that the link is not registered in the routing file and I replace it with the route of the form. This way it goes, but the selection of cities is always empty, so there is still a failure.