I have selector in a form. This selector has default data, but I need to show some data depending on who is accessing this form. The problem is when someone is to access it the first time, the selector doesn't refresh but it refreshes correctly when it is accessed the second time.

How I can do it to refresh on the first time?

I'm using selectpicker with jQuery and I get data through JSON

 var _loadProjectSelector = function (data, valProjecte) {
        $(juniper.specialProjects.intranet.selectors.MODAL.INCIDENTPROJECT_SELECT).html('');
        var toAppend = '<option disabled selected="true" value=""> -- Selecciona un Proyecto -- </option>';
        $.each(data, function (id, value) {
            toAppend += '<option data-subtext="' + value.P_codi + '" value="' + value.P_codi + '">' + value.P_nom + '</option>';                
        });
        $(juniper.specialProjects.intranet.selectors.MODAL.INCIDENTPROJECT_SELECT).append(toAppend).junSelect({
            Config: {
                autocomplete: true,
                size: 14
            }
        });
        $(juniper.specialProjects.intranet.selectors.MODAL.INCIDENTPROJECT_SELECT).selectpicker('val', valProjecte);
        return true            
    };

var _getProjectSelector = function (dataProjecte, valprojecte) {          
        $.ajax({
            url: window.baseUrl + '/incident/ajax/regularIncidentManagement.ashx',
            async: true,
            data: dataProjecte,
            dataType: "json",
            type: 'POST',
            success: function (result) {                    
                if (result.StatusOk) {
                    if (_loadProjectSelector(result.Result, valprojecte) == true) {                       
                        $(juniper.specialProjects.intranet.selectors.MODAL.INCIDENTPROJECT_SELECT).selectpicker('refresh');                         
                        $('.modal-body').show();
                        $('.it_modalLoad').hide();
                    }

                } else {
                    juniper.specialProjects.intranet.Notifications.showErrorNotification(result.ErrorMessage);
                }
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                juniper.specialProjects.intranet.Notifications.showErrorNotification("Se ha producido un error");
            }
        });
    };

I hope that the change is reflected in the first instance

Related posts

Recent Viewed