Set value to select2 ajax input
Set value to select2 ajax input
itarodrigo
Posts: 15Questions: 6Answers: 0
My code:
{ label: "Município de Residência:", name: "tb_cidadao.ibge", type: "select2", opts: {
placeholder: "Selecione o município",
initialValue: true,
ajax: {
url: 'dados/localidade.php',
dataType: 'json',
delay: 250,
processResults: function(data){
return{
results: data
};
},
cache: true
}
}},
I am trying to set a value to my select2 field using the code below, but it's not works and not generate any error:
editor.field('tb_cidadao.ibge').inst().select2().val('2605004').trigger('change');
Edited by Allan - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
I'd suggest using
field().val()
to set the value - e.g.If that doesn't help, can you post a link to a test case showing the issue please?
Allan