0
I have a Select2 that is populated from the database of everything working, receives the data of the bank and etc. however if I want to edit it does not bring the saved option on the screen only on the front if debug it is there, already normal select it brings face understand
this is javascript
$('.js-single').select2({
allowClear: true,
selectOnClose: true,
})
this and html
<div class="es2 col-md-6">
<label class="lb">País<label class="lb1" data-
toggle="tooltip"
title="ÁREA DE TEXTO OBRIGATÓRIO"> *</label></label>
<select data-toggle="tooltip"
title="ÁREA DE TEXTO OBRIGATÓRIO" required="required"
ng-model="pessoa.pessoasEnderecos.pais.idPais"
ng-options="pai.idPais as pai.nome for pai in paises "
class="js-single"
style="width: 100%; margin-top: -10px;" id="paisPais">
<option ></option>
</select>
</div>
if anyone can help me
Hello. already tried to force change after value change?
$('#paisPais').trigger('change');
? maybe due to the angular the update is not triggering the change Trigger and the value does not appear on the screen.– h3nr1ke
Yes already tried, but when entering the modal nothing appears, only if I select the select then the correct option appears within a span. but in case it has to appear at the time I click edit open the modal and this is the option saved by the user, understand.
– Diego Laura Soares
Researching a little I saw this reply that says we use another event
$('#paisPais').trigger('change.select2');
maybe it works.– h3nr1ke
I took the test here on the select website and it really works when we use
$('#paisPais').trigger('change.select2');', primeiro mudei o valor direto utilizando
val("value")e nada mudou no select, depois do
Trigger('change.Select2');` value has been updated in span.– h3nr1ke