Change select2 dinamicaly
Change select2 dinamicaly
itarodrigo
Posts: 15Questions: 6Answers: 0
I have an code:
{ label: "Escola:", name: "rl_usuario_escola_turma_disciplina.escola_id", type: "select2", opts: {
placeholder: "Selecione a escola",
initialValue: true,
ajax: {
url: 'assets/dados/data_escola.php',
dataType: 'json',
delay: 250,
processResults: function(data){
return{
results: data
};
},
cache: true
}
}},
{ label: "Turma:", name: "rl_usuario_escola_turma_disciplina.turma_id", type: "select2", opts: {
placeholder: "Selecione a turma",
initialValue: true,
ajax: {
url: 'assets/dados/data_turma.php',
dataType: 'json',
delay: 250,
processResults: function(data){
return{
results: data
};
},
cache: true
}
}},
I need change the select2 opts of the field rl_usuario_escola_turma_disciplina.turma_id when I change the field rl_usuario_escola_turma_disciplina.escola_id.
I try this:
editor.field('rl_usuario_escola_turma_disciplina.escola_id').input().on('change', function(){
escola_id = editor.field('rl_usuario_escola_turma_disciplina.escola_id').val();
editor.field('rl_usuario_escola_turma_disciplina.turma_id').input().opts({
placeholder: "Selecione a turma",
initialValue: true,
ajax: {
url: 'assets/dados/new.php',
dataType: 'json',
delay: 250,
processResults: function(data){
return{
results: data
};
},
cache: true
});
});
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
You would use
dependent()
to then get the different values for that other Select2 element - the change to the first would trigger the update to the second.Colin
Can you post a example please?
You likely will find some examples on the forum. Here is one thread that might give you a start.
Kevin