Skip to content
This repository was archived by the owner on Oct 2, 2019. It is now read-only.

Keep Placeholder activated in multipleSelect component #1796

Closed
fabioel opened this issue Sep 7, 2016 · 11 comments · Fixed by #2015
Closed

Keep Placeholder activated in multipleSelect component #1796

fabioel opened this issue Sep 7, 2016 · 11 comments · Fixed by #2015

Comments

@fabioel
Copy link

fabioel commented Sep 7, 2016

Hello!
I stumbled upon a problem today that is caused by the following lines:
uiSelectMultipleDirective.js

ctrl.getPlaceholder = function(){
        //Refactor single?
        if($select.selected && $select.selected.length) return;
        return $select.placeholder;
      };

I would like to have my placeholder activated even after I selected the first option in a multiple select component. Is there a plan to refactor this? Maybe to use a property like: keepPlaceholder

Thanks!

@user378230
Copy link
Contributor

user378230 commented Oct 28, 2016

See discussion in #1433

Can you put together a PR with tests for it?

@DmitryGonchar
Copy link
Contributor

DmitryGonchar commented Mar 14, 2017

@user378230 Which approach is better to fix this?

Should we move getPlaceholder() to uiSelectSingle and change $selectMultiple.getPlaceholder() to $select.getPlaceholder() in all three templates?

Or, another option is to add

if($select.getPlaceholder)
          return $select.getPlaceholder();

into existing function

@Jefiozie
Copy link
Contributor

Hi @DmitryGonchar I think it is best to go for the first option. Are you going to make the PR?

Thanks.

@DmitryGonchar
Copy link
Contributor

@Jefiozie I will have time only at the weekend. Are you sure option 1) will not break some other use cases? Or is it all covered with tests?

@moussa-b
Copy link

moussa-b commented Mar 27, 2017

Hi, I would also need this feature for ui-select multiple, I have navigated through the three tickets concerning this feature (the current one, #1433 and #1612). And I am not sure, the feature is present for ui-select non-multiple and not present for ui-select multiple, that's it?

I am asking that because I have tried to get this work but didn't managed to. Here is a plunker : http://plnkr.co/edit/u5sNZ77dtaXMht3uTcnw?p=preview

@moussa-b
Copy link

Any update on that ticket please?

@DmitryGonchar
Copy link
Contributor

@Jefiozie what about answers for #1796 (comment)?

Option 2 seems to be a safer one if you are not sure

DmitryGonchar added a commit to DmitryGonchar/ui-select that referenced this issue Jun 17, 2017
User can provide their custom `getPlaceholder()` function. E.g. to keep placeholder activated in multipleSelect component, you can use this one:
```
angular.module('myApp').directive('myAppUiSelectPlaceholderAlwaysVisible', function() {
  return {
    require: 'uiSelect',
    link: function($scope, $element, attrs, $select) {
      $select.getPlaceholder = function () {
        return $select.placeholder;
      }
    }
  }
});
```
And then add this directive to the `<ui-select>` html element

closes angular-ui#1796
@DmitryGonchar
Copy link
Contributor

DmitryGonchar commented Jun 17, 2017

@fabioel and others
When this PR is merged - you can get the desired behavior (on demand) with something like this:

angular.module('myApp').directive('myAppUiSelectPlaceholderAlwaysVisible', function() {
  return {
    require: 'uiSelect',
    link: function($scope, $element, attrs, $select) {
      $select.getPlaceholder = function () {
        return $select.placeholder;
      }
    }
  }
});

And then add this directive as an attribute to the <ui-select my-app-ui-select-placeholder-always-visible> html element where this behavior is needed

Or you can override this function globally, of course

DmitryGonchar added a commit to DmitryGonchar/ui-select that referenced this issue Jun 17, 2017
User can provide their custom `getPlaceholder()` function. E.g. to keep placeholder activated in multipleSelect component, you can use this one:
```
angular.module('myApp').directive('myAppUiSelectPlaceholderAlwaysVisible', function() {
  return {
    require: 'uiSelect',
    link: function($scope, $element, attrs, $select) {
      $select.getPlaceholder = function () {
        return $select.placeholder;
      }
    }
  }
});
```
And then add this directive to the `<ui-select>` html element

closes angular-ui#1796
@moussa-b
Copy link

moussa-b commented Jul 5, 2017

Hi @DmitryGonchar thanx for your fix I have tested it locally by copying/pasting your code, and it works well. Any idea when is scheduled the next release with your pull request? This ticket is nearly one year old

@DmitryGonchar
Copy link
Contributor

DmitryGonchar commented Jul 6, 2017

No idea. When @Jefiozie merges it, I am not the maintainer.

@rhyskoedijk
Copy link

+1 on merging this please. @Jefiozie

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants