isteven / angular-multi-select

A multi select dropdown directive for AngularJS. Allows you to use HTML tags and CSS in the data. Requires only AngularJS and nothing else.
isteven.github.io/angular-multi-select
MIT License
1.08k stars 516 forks source link

Support label formatters #243

Open slavafomin opened 9 years ago

slavafomin commented 9 years ago

Allow function to be passed to the button-label-formatter and item-label-formatter attributes.

When component will need to generate the label for button or item, it will call this function (we can call such a function «label formatter») and pass actual item element[s] to it.

Example

function controller ($scope) {
  $scope.elementList = [
    { firstName: 'Slava', lastName: 'Fomin', email: 's.fomin@betsol.ru' }
    // ...
  ];
  $scope.itemLabelFormatter = function (item) {
    return (item.firstName + ' ' + item.lastName + ' <' + item.email + '>');
  }
}
<isteven-multi-select
    input-model="elementList"
    item-label-formatter="itemLabelFormatter"
>
</isteven-multi-select>

It will allow developers to dynamically format labels as they see fit.

Of course we can pre-generate this labels for each item manually, but such API will make it more ellegant and friendly in my opinion and will leave original list untouched (visualization data should not be mixed with original data).

isteven commented 9 years ago

Hi @slavafomin ,

Thanks for the idea. Actually my goal is to allow user to inject their own HTML template (a la $templateCache thing), but we'll see. For now seems that most of the users are happy with what's available. .

slavafomin commented 9 years ago

You should consider that most of the people will never tell or even understand what they really need. Some people will just skip the library if they will not like it's implementation.

The template approach looks promising however.

isteven commented 9 years ago

I totally respect their decision to use, modify, or skip my library :)

tedyoung commented 9 years ago

+1 on injecting HTML or some other mechanism to control the formatting (I was making similar modifications in my fork).

tufan-yoc commented 9 years ago

+1 for label formatters. Current pre generated labels simply don't look good on some designs.

I totally respect their decision to use, modify, or skip my library :)

telling users to go to "somewhere else", is not "nice", also not the right approach for a product development.

aljamala commented 9 years ago

I agree, I've been integrating your directive, but after reading some of your comments regarding proposed updates (which would definitely make it more robust), I am reconsidering my choice. It seems I can't even add brackets for my labels? Which is a common way to represent abbreviations.

isteven commented 9 years ago

Hi @aljamala ,

I did put brackets in my string data (in some of earlier examples). No problem with them.

aljamala commented 9 years ago

It's not the data that contains brackets. For example I want to be able to do the following: item-label="name (abbreviation)", and I don't see that output unless I remove the brackets.

isteven commented 9 years ago

@aljamala ,

Oh, that.. You are correct, at the moment they are not supported.

RyanPicanco commented 9 years ago

I've forked this and made the button and itemLabels be a template type string. Feel free to use that solution if you like.

chris-wood-dynmark commented 9 years ago

+1 for label formatting, I am having to consider using another directive purely because I cannot display the items on two lines in the select list e.g Name Description

I could use a fork like the one above but it is not the policy here to do that

simonered commented 9 years ago

+1 for label formatting

jrahulroy commented 8 years ago

+1

rbordeanu commented 8 years ago

+1

mitomm commented 6 years ago

+1

miriame commented 6 years ago

+1