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

on-remove and on-select should fire AFTER addition/removal of the item. #463

Closed
gotenxds opened this issue Dec 2, 2014 · 10 comments
Closed

Comments

@gotenxds
Copy link

gotenxds commented Dec 2, 2014

I have a list of entities, each entity has a list of items, those items are the ones I'm displaying to the user in multiple mode.

When the user removes or adds and item to the list the on-action event fires, but it fires before the removal\addition of the item from the list, so I can not send my entity for update in the DB.

Side note: This will also compliment the way ui-grid works on edit.
Example to what I mean:

html:

<ui-select multiple ng-model="exemption.selected.dutyTypes" theme="select2" on-remove="update" >

script (pseudo code):

$scope.update = function(){
     $http.put("/exemptions/", exemption.selected); // cant do this because the item is not updated yet!!!
}
@brianfeister
Copy link

@gotenxds thanks for your explanation - to expedite the process you could consider posting a Plunkr test case that demonstrates the problem.

@olegweb
Copy link

olegweb commented Dec 4, 2014

$timeout(function(){ctrl.onSelectCallback($scope, {
$item: item,
$model: ctrl.parserResult.modelMapper($scope, locals)
});
});

brianfeister pushed a commit that referenced this issue Dec 8, 2014
@brianfeister
Copy link

I've moved the callback at the referenced commit for the onSelectCallback, however, the onRemoveCallback appears to already be in the correct place. Please post a demo of the feature breaking because without demonstration, it looks to me like an execution runtime issue that you would need to manage on your end.. Also, make sure to use the latest (v0.9.3 at the time of this comment)

@gotenxds
Copy link
Author

gotenxds commented Dec 8, 2014

Hi, here I made a plunker test: http://plnkr.co/edit/5czQ6iNn4dVMCcVf9ALr?p=preview

on-remove alerts the length on the list.
As you can see this is as I described.

@brianfeister
Copy link

Thanks @gotenxds. Some more critical bugs have kept me busy and I'm busy at my day job right now. Feel free to open a PR that fixes this. The short explanation is that the callback is firing after the ctrl.selected has it's new value, but before the change is propagated to the external $scope model (in your example $scope.multipleDemo.selectedPeople) we have a race condition and the callback is called prior to updating the intended target selectedPeople.

@brianfeister brianfeister reopened this Dec 8, 2014
@karser
Copy link

karser commented Dec 11, 2014

+1

@karser
Copy link

karser commented Dec 11, 2014

workaround is to use $timeout with 100 ms

@ilanbiala
Copy link

I think this is fixed now, but it would be great if someone else could confirm.

@brianfeister
Copy link

Resolved by #501

@saurabhsoni14
Copy link

how to get only ID and post in database

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

No branches or pull requests

6 participants