ui-select icon indicating copy to clipboard operation
ui-select copied to clipboard

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

Open gotenxds opened this issue 12 years ago • 10 comments

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!!!
}

gotenxds avatar Dec 02 '14 20:12 gotenxds

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

brianfeister avatar Dec 03 '14 15:12 brianfeister

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

olegweb avatar Dec 04 '14 09:12 olegweb

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)

brianfeister avatar Dec 08 '14 17:12 brianfeister

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.

gotenxds avatar Dec 08 '14 18:12 gotenxds

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 avatar Dec 08 '14 20:12 brianfeister

+1

karser avatar Dec 11 '14 17:12 karser

workaround is to use $timeout with 100 ms

karser avatar Dec 11 '14 17:12 karser

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

ilanbiala avatar Jan 23 '15 15:01 ilanbiala

Resolved by #501

brianfeister avatar Feb 18 '15 20:02 brianfeister

how to get only ID and post in database

saurabhsoni14 avatar Apr 11 '19 11:04 saurabhsoni14