set Value of select mobius not working javascript

Viewed 10

good afternoon, have all of you, I have this problem. I am using selectr mobius1 and when I click to edit data, the "Type of Service" field does not show me the value that it should show me.

my select is initialized like this

$selecttSE = new Selectr("#tipo_SAPIE",{});

I use this onchange so that when a product is chosen the list of services changes

$("#tipo_productoE").on('change', function() {
    var tipoprod = $("#tipo_productoE option:selected").val();
    var select_servapi = $("#tipo_SAPIE");
    $.ajax({
        url: '<?= base_url('productos/select_servicios') ?>',
        type: 'get',
        data: {
            tipoprod: tipoprod
        },
        beforeSend: function(){
            
          $selecttSE.removeAll();
        },
        success: function(response) {

            if (response.length >2 ) {
                select_servapi.attr('disabled', false);
              
                $.each(JSON.parse(response), function(i, item) {
                    $selecttSE.add([{
                        value: item.servicioapiid,
                        text: item.alias+'    '+item.moneda+''+item.costo}])
                  
                });
                let select = $("#tipo_SAPIE").parents().children('small')[0];
                $(select).empty();
                $(select).html('Requerido');
                $(select).addClass('badge badge-soft-danger');
            } else {
                select_servapi.attr('disabled', true);
                
            }

        },
    });
});

And my function to get the data is this

function getProducto(idproducto) {
var idproducto = idproducto;
$.ajax({
    url: '<?= base_url('productos/getProducto') ?>',
    type: 'GET',
    data: {
        idproducto: idproducto
    },
    success: function(response) {
        console.log(response)
        $selecttSE.removeAll();
        $.each(JSON.parse(response), function(i, item) {
            document.getElementById("tipo_productoE").value = item.tipoproductoid;
            $("#tipo_productoE").trigger('change');
            $selecttSE.setValue(item.servicioapiid);
        });
    },
    error: function(errors) {

    },
});

}

Thank you for taking the time to see my post have a great afternoon and much success.

0 Answers
Related