ui-select2 icon indicating copy to clipboard operation
ui-select2 copied to clipboard

updates hidden input placeholder binding don't update select2 placeholder

Open lanterndev opened this issue 12 years ago • 7 comments

Given something like

<input type="hidden" placeholder="{{ PLACEHOLDER | translate }}" ui-select2="select2opts" ...>

the select2's placeholder is initially rendered correctly, but if the value of {{ PLACEHOLDER | translate }} changes after the select2 has been initialized (e.g. because the user has changed her language setting), the select2's placeholder is not updated to match the hidden input's.

lanterndev avatar Aug 16 '13 16:08 lanterndev

Did found a solution for this issue ?

msalahz avatar Jan 22 '14 14:01 msalahz

Bump, i have same issue here. I am using angular-translate (with messageformat) and this placeholder is not changing with translate filter.

nehaleem avatar Feb 21 '14 10:02 nehaleem

I have the same problem, i would like to translate the select2 with angular-translate.

bluesky777 avatar Mar 27 '14 20:03 bluesky777

+10 Same problem here - renders Select2 unusable for our angular application.

BerndWessels avatar May 02 '14 02:05 BerndWessels

I found a solution, i just made some minor modification add scope: { ready: "=" },

            //Fix to ensure translations or data are ready
            if (scope.ready == undefined) {
                initialize();
            } else {
                scope.$watch('ready', function(newVal) {
                    if (scope.ready) {
                        initialize();
                    }
                });
            }

            function initialize() {
                // Initialize the plugin late so that the injected DOM does not disrupt the template compiler
                $timeout(function () {
                    elm.select2(opts);

                    // Set initial value - I'm not sure about this but it seems to need to be there
                    elm.select2('data', controller.$modelValue);
                    // important!
                    controller.$render();

                    // Not sure if I should just check for !isSelect OR if I should check for 'tags' key
                    if (!opts.initSelection && !isSelect) {
                        var isPristine = controller.$pristine;
                        controller.$setViewValue(
                          convertToAngularModel(elm.select2('data'))
                        );
                        if (isPristine) {
                            controller.$setPristine();
                        }
                        elm.prev().toggleClass('ng-pristine', controller.$pristine);
                    }
                });
            }

stherrienaspnet avatar Jun 19 '14 13:06 stherrienaspnet

I fixed by adding this code in the angular-ui-select2.js

  return function (scope, elm, attrs, controller) {

  attrs.$observe('placeholder', function(newValue) {
      if(typeof elm.select2("val") == 'string' && elm.select2("val")=="")
        $(elm.select2("container")).find(".select2-chosen").html(newValue);

      if(Array.isArray(elm.select2("val")) && elm.select2("val").length==0)
        $(elm.select2("container")).find(".select2-default").val(newValue);

  });

Blazej

blazejgrzelinski avatar Dec 02 '14 12:12 blazejgrzelinski

Thank you!

On Tue, Dec 2, 2014 at 7:52 AM, Blazej [email protected] wrote:

I fixed by adding this code in the angular-ui-select2.js

return function (scope, elm, attrs, controller) {

attrs.$observe('placeholder', function(newValue) { if(typeof elm.select2("val") == 'string' && elm.select2("val")=="") $(elm.select2("container")).find(".select2-chosen").html(newValue);

  if(Array.isArray(elm.select2("val")) && elm.select2("val").length==0)
    $(elm.select2("container")).find(".select2-default").val(newValue);

});

Blazej

— Reply to this email directly or view it on GitHub https://github.com/angular-ui/ui-select2/issues/59#issuecomment-65226264 .

stherrienaspnet avatar Dec 02 '14 15:12 stherrienaspnet