bentorfs / angular-bootstrap-multiselect

Native angularJS custom form element
http://bentorfs.github.io/angular-bootstrap-multiselect/
MIT License
79 stars 111 forks source link

Added option to preselect an item #62

Open Mattie112 opened 6 years ago

Mattie112 commented 6 years ago

By filling the $scope.resolvedOptions in both methods we can "preselect" some items.

example:

// You can add this in your app.js
$scope.options = [ {id: 1, foo: "bar"}, {id: 2, bar: "foo"} ];
$scope.selection = [ {id: 1, foo: "bar"} ];

When you load your webpage the item with id 1 is already selected

EzequielMoroni commented 6 years ago

Worked fine. Thanks!

zeroxm commented 6 years ago

Was this merged on master?

I need this so all options come pre-selected and the user filters then out, instead of selecting then.

May be an odd behavior, I know, but it's what was requested.

Mattie112 commented 6 years ago

As far as I know this is not merged, but feel free to my fork.

zeroxm commented 6 years ago

@Mattie112 , could you help me on how to use this?

I have someting like this:


<multiselect ng-model="filtro.clientes" 
                 options="clientes" 
                 id-prop="id" 
                 display-prop="nome"
                 name="cliente"
                 labels="labelsClientes"
                 show-select-all="true"
                 required>```

How do I set all options as selected?
Mattie112 commented 6 years ago

Simply set it in your JS code :)

<multiselect ng-model="selection" 
                 options="options" >
// You can add this in your app.js
$scope.options = [ {id: 1, foo: "bar"}, {id: 2, bar: "foo"} ];
$scope.selection = [ {id: 1, foo: "bar"} ];
zeroxm commented 6 years ago

Oh yup, it's simple, Thanks! You're awesome!

Mattie112 commented 6 years ago

No probs! Have fun with it!

gdejong commented 6 years ago

I'd love to use this feature, any updates on merging this in the master @bentorfs?