I have this script, which when selecting a state, it loads the counties that are working, but if I try to save by a submit action it shows the error. But what the user chose in the municipality goes away, and the municipalities go blank.
<script type="text/javascript">
$(function() {
$('#estadoMunicipio')
.change(
function() {
if ($(this).val()) {
$('#municipioEstado').hide();
$('.carregando').show();
$.getJSON('/nota-fiscal-servico-web/buscaMunicipioPorPaisEstado/' + $(this).val(),
function(j) {
var options = '<option value="" class="chosen-select">'
+'</option>';
for (var i = 0; i < j.length; i++) {
options += '<option class="chosen-select" value="' +
j[i].id + '">'
+ j[i].descricao
+ '</option>';
}
$('#municipioEstado')
.html(options)
.show();
$('.carregando').hide();
});
} else {
$('#municipioEstado')
.html(
'<option class="chosen-select" value="">-- Escolha um estado --</option>');
}
});
});
</script>