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

on-select-all="fSelectAll()"

Open karthicjayaraman opened this issue 10 years ago • 20 comments

output-model is not updated when using on-select-all property.

It would be very helpful for me if you could provide how to get the length of the output-model when select the " on-select-all" option.

karthicjayaraman avatar Jun 26 '15 21:06 karthicjayaraman

Hi @karthicjayaraman ,

Can you please help to replicate the problem in JsFiddler or Plunker?

isteven avatar Jun 29 '15 03:06 isteven

Can reproduce here. The output model is updated, but only AFTER the on-select-all callback has occurred. We need to do a $watch on the output model instead, which to me seems dirty.

JeffreyATW avatar Jun 30 '15 23:06 JeffreyATW

@JeffreyATW ,

I see.. so in other words, during on-select-all callback, the output-model is NOT YET updated (still showing old values)?

Does this also happen in on-select-none?

  • Edit: I prefer not to $watch output-model here.. There are 2 $watches inside the code and I believe it's enough.

isteven avatar Jul 01 '15 01:07 isteven

Yes, happens in both.

JeffreyATW avatar Jul 01 '15 04:07 JeffreyATW

@JeffreyATW , @karthicjayaraman

Thanks for the info. This is what I'm afraid most.. it happened before, and it forced me to use the $timeout. I'll see what I can do about this.

isteven avatar Jul 01 '15 08:07 isteven

Great .. Thanks a lot for the response .

On Wed, Jul 1, 2015 at 1:59 AM, Steven [email protected] wrote:

@JeffreyATW https://github.com/JeffreyATW , @karthicjayaraman https://github.com/karthicjayaraman

Thanks for the info. This is what I'm afraid most.. somehow the changes is not yet reflected back at the controller. I'll see what I can do about this.

— Reply to this email directly or view it on GitHub https://github.com/isteven/angular-multi-select/issues/307#issuecomment-117550162 .

karthicjayaraman avatar Jul 06 '15 07:07 karthicjayaraman

I had the same issue but it is solved when you specify property of what should be updated in output model:

output-properties="id name ticked"

lenczykt avatar Jul 30 '15 08:07 lenczykt

Nope, we have that set. It works for on-item-click but not on-select-all or on-select-none.

JeffreyATW avatar Jul 30 '15 16:07 JeffreyATW

Hi all,

Sorry but my current project leaves me almost no time to update the directive.

@JeffreyATW , does $watch-ing the output-model work?

isteven avatar Jul 30 '15 16:07 isteven

Yes.

JeffreyATW avatar Jul 30 '15 17:07 JeffreyATW

changing a line worked for me.

this line: $scope.onSelectAll();

to this:

$timeout( function() { $scope.onSelectAll(); }, 0 );

prabuinet avatar Oct 20 '15 11:10 prabuinet

Hi all,

I recently hit similar problem in a complex page, and, after browsing around, one possible solution is simply to add child object on the output-model, like this:

<isteven-multi-select
    input-model="someData" 
    output-model="awesomeOutput.data"    // Add .data
    tick-property="status" 
    on-select-all="showSelected()" 
    ....

Then in your controller, as usual:

$scope.showSelected = function() {
    console.log( $scope.awesomeOutput.data );
}

I hope this helps.

@prabuinet , I personally don't think the $scope.onSelectAll() function should be enclosed within $timeout as it does not involve complex DOM operation (it's just a button click afterall). But hey, as long as it solves the problem :sunglasses: :thumbsup:

Further reading: http://juristr.com/blog/2014/11/learning-ng-databinding-doesnt-work/

isteven avatar Oct 28 '15 12:10 isteven

I am still having issue with this for both the select-all and select-none. Has it not been resolved? If not, what $watch statement do you recommend?

Thanks.

astropcrb avatar Feb 25 '16 19:02 astropcrb

@astropcrb ,

Does adding child object on the output-model work for you?

<isteven-multi-select
    input-model="someData" 
    output-model="awesomeOutput.data"    // Add .data
    tick-property="status" 
    on-select-all="showSelected()" 
    ....

Then in your controller, as usual:

$scope.showSelected = function() {
    console.log( $scope.awesomeOutput.data );
}

isteven avatar Feb 26 '16 01:02 isteven

Hi !

I also have the same problem, but only for on-select-all. I tried your solution by adding a child object and a log in the controller, but it does not work for me.

Any update :) ?

CaptainYouz avatar Mar 17 '16 11:03 CaptainYouz

Thanks for the great directive but I am still having issue with this for both the select-all and select-none. Any plans on fixing this?

mgalic avatar Apr 28 '16 06:04 mgalic

Here's a fix for this issue: https://github.com/isteven/angular-multi-select/pull/461

ctcudd avatar Jul 19 '16 14:07 ctcudd

Any ideas what is best way to intercept click event on "Select All" button? As I read few comments above, using another $watch will make my code stink.

What I want to achieve, is catch click event on "Select All" button and either accept if some conditions are met or block and reject the operation of selecting all objects.

Docs for on-select-all states:

A $scope function to call when "select all" button is clicked. You need to define this function in your controller.

but it's not clear to me, the callback on-select-all is triggered before, at the same time or after the item is clicked?

ghost avatar May 09 '17 13:05 ghost

@aryniec,

It's triggered after all items' selection property is set to TRUE.

Generally speaking, all events are triggered after the selection changes happen.

isteven avatar May 09 '17 23:05 isteven

@isteven then what would be best way to intercept this "Select All" click, both Angular 1.5 and angular-multi-select way?

ghost avatar May 10 '17 08:05 ghost