I have a tag with some bootstrap properties and I want to select an spcific option when I press Edit link, but at now It doesn't work, other fields works but selects always get default option.
Select
<div class="form-group">
<select id="categoryField" form="formPerson" class="form-control select2me" placeholder="Categoría" th:field="*{category}">
<option value="-1">Categoría</option>
<option th:each="cat : ${categorias}" th:value="${cat.id}" th:text="${cat.name}"></option>
</select>
</div>
Script
function editJury(year, category, juryType, accepted, acceptDate, notes, index){
$('#categoryField option[value="'+category+'"]');
$('#yearField').val(year);
$('#juryTypeField').val(juryType);
$('#dateField').val(acceptDate);
if(accepted==1){
$('#radio6').val(accepted);
}
if(accepted==0){
$('#radio7').val(accepted);
}
if(accepted==null){
$('#radio8').val(accepted);
}
$('#notesField').val(notes);
$('#indexField').val(index);
}
I tried this but doesn't work for me, I think it's because when I inspect the final html bootstrap transform the select tag in a div...
EDIT: I change completly how to edit this, and now I'm thinking will be better not use so much JQuery, so now I have 2 problems, first, I can get the selected value correctly (always stay in default -1) and the modal dialog not opens when page loads.
At now, when you click this
<a class="edit" href="#modal-jury-form" th:href="@{/person/edit_jury/__${status.index}__}" data-toggle="modal">Editar </a>
Launch the controller method:
@RequestMapping(value = "person/edit_jury/{index}", method = RequestMethod.GET)
public String editJury(@PathVariable String index, @ModelAttribute("person") PersonForm personForm,
RedirectAttributes ra, Model model) {
Jury jury = personForm.getJuries().get(Integer.parseInt(index));
personForm.setJuryAux(new JuryForm(jury));
model.addAttribute("person", personForm);
return "person/new";
}
Then return to page but modal doesn't load automatically... but if you click in New button, modal loads with the data that I passed except for the tags whose load default option.