0
Talk, you guys, baby?
I’m having a hard time. I have a modal, and wanted when making a select change, to press via ajax, to feed a jQuery multiselect. In a console.log
I can see the output of options, but I cannot insert them into the Multiselect block.
Does this happen because of the DOM you’ve already loaded and I can’t fill it out anymore? I can’t get around it. My code looks like this:
In modal:
<div class="modal-body">
<div class="container">
<div class="row">
<div class="col-md-8">
<div class="form-group">
<label for="modulo" class="control-label">Nome do Curso</label>
<input type="text" class="form-control" id="modulo" name="modulo" required/>
</div>
</div>
<div class="col-md-2">
<div class="form-group">
<label for="tipo_modulo" class="control-label">Tipo do Módulo</label>
<select class="form-control" id="tipo_modulo" name="tipo_modulo" required>
<option disabled selected value="">Selecione um Tipo</option>
<option value="basico">Básico</option>
<option value="especifico">Específico</option>
</select>
</div>
</div>
<div class="col-md-2">
<div class="form-group">
<label for="carga_horaria" class="control-label">Carga Horária</label>
<input type="number" class="form-control" id="carga_horaria" name="carga_horaria" required/>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="form-group">
<label for="nome_curso" class="control-label">Descrição do Módulo</label>
<textarea class="form-control" id="descricao_curso" name="descricao_curso" required></textarea>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="form-group">
<label for="id_disciplina" class="control-label">Disciplinas Disponíveis</label>
<select name="id_disciplina" class="multi-select" multiple="" id="my_multi_select3">
<div class="disciplinas"></div>
</select>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default waves-effect" data-dismiss="modal">Fechar</button>
<button type="submit" class="btn btn-info waves-effect waves-light">Cadastrar Módulo</button>
</div>
In my JS who does the ajax:
$("#tipo_modulo").change(function(){
let tipo = $(this).children("option:selected").val();
$.ajax({
url: '../../assets/ajax/disciplinas.php',
method: 'POST',
data: {modo: tipo},
dataType: 'html',
success: function (result) {
$(".disciplinas").html(result);
}
});
});
And in my file disciplines.php I already do a database search with my class already printing the options:
<?php
require('../../_app/Config.inc.php');
$post = filter_input_array(INPUT_POST, FILTER_DEFAULT);
if($post['tipo'] == 'basico'){
$ReadDiscipline = new Read();
$ReadDiscipline->ExeRead("disciplinas", "WHERE ativo = 1");
foreach ($ReadDiscipline->getResult() as $disc):
echo "<option value='{$disc['id']}'>{$disc['nome_disciplina']}</option>";
endforeach;
}
What I want to fill in is this Multiselect field:
If anyone can give me a light I’ll be very grateful kkkk =P Hug to all.
Is this Rafael blz?
<div class="disciplinas"></div>
within theselect
? Why you try to include the options within theselect
direct I think this way will work– Thiago Costa
Blz Thiago and you? I tried to use that
<div>
to create only the<options>
in place. I tried as mentioned yet it does not feed the box. I tried also in my php already bring all html from the<select>
still doesn’t work. It’s like the multiselect box only loads on the first page load.– Rafael