Base solution for your next web application
Open Closed

Problem setting value in a bootstrap-select #2797


User avatar
0
bilalhaidar created

Hi, I am using bootstrap-select in an angular js project.

Loading data inside the select control works fine. Now it is time to set a value from backend angular js.

The problem is the angular model is changing, but the change is not reflected on the client UI. Here is the code.

...
vm.poc = poc;

//Refresh all selects
refreshSelects();

            var selectIds = {
                shelters: '#Shelter',
...
            };

function refreshSelects() {
   //Loop over all select ids from the selectIds
   //and trigger a refresh
   .each(selectIds, function (value) {
         $timeout(function () {
              $(value).selectpicker('refresh');
          }, 0);
  });
 }

5 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    Can you share the html part for your select item ?

    Thanks.

  • User Avatar
    0
    bilalhaidar created

    Hi Ismail,

    The problem was the bootstrap-select expects values to be "strings". In my case, I retrieve the value as Int from the server. I had to convert those values to strings, then they work fine. Is that normal?

    Something else I got, the form was hanging and getting angular errors of infinite $digest cycles. I was creating functions to control ng-show, and inside those functions I am resetting fields to be hidden, but that was causing many $digest cycles. How would I control show/hide and when hidden to clear the value so that it doesn't get submitted to server?

    Thanks

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    Normally ng-show should work and invisible controls are not sent to server. Can you share a bit of code, so I will try to understand the cause of problem.

    Thanks.

  • User Avatar
    0
    bilalhaidar created

    It's a huge form. I can share the application by email.

    I read somewhere ng-if would remove the element from DOM, which is better so that the element will be submitted to server as empty.

    The problem I believe is due to so many digest cycles.

    Thanks

  • User Avatar
    0
    ismcagdas created
    Support Team

    Please send the project and explain how can I reproduce the problem.

    Thanks.