angular-multi-select icon indicating copy to clipboard operation
angular-multi-select copied to clipboard

Support label formatters

Open slavafomin opened this issue 10 years ago • 16 comments

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: '[email protected]' }
    // ...
  ];
  $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).

slavafomin avatar Mar 19 '15 11:03 slavafomin

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. .

isteven avatar Mar 19 '15 14:03 isteven

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.

slavafomin avatar Mar 19 '15 15:03 slavafomin

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

isteven avatar Mar 19 '15 15:03 isteven

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

tedyoung avatar Mar 20 '15 02:03 tedyoung

+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.

tufan-yoc avatar Apr 08 '15 08:04 tufan-yoc

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.

aljamala avatar May 07 '15 17:05 aljamala

Hi @aljamala ,

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

isteven avatar May 07 '15 17:05 isteven

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.

aljamala avatar May 07 '15 17:05 aljamala

@aljamala ,

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

isteven avatar May 07 '15 18:05 isteven

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

RyanPicanco avatar May 29 '15 18:05 RyanPicanco

+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

chris-wood-dynmark avatar Nov 23 '15 17:11 chris-wood-dynmark

+1 for label formatting

simonered avatar Dec 03 '15 17:12 simonered

+1

jrahulroy avatar Sep 21 '16 01:09 jrahulroy

+1

rbordeanu avatar Oct 05 '16 13:10 rbordeanu

+1

mitomm avatar Apr 20 '18 19:04 mitomm

+1

miriame avatar Apr 30 '18 06:04 miriame