Do something when @this.call finish

Hi everyone!

I’m using the @this.call to chain an action from another component when i change the option of an select2 input, i’m trying to do some stuff after the call finish but i don’t know how to do this, i fix it with this code but it doesn’t meant to be the best way for make it.

            .on('select2:select', function (e) {
            	@this.set('selected',e.params.data.id);
            	@this.call('increment');

                setTimeout(function(){
                    $('.gender').select2();

                    $('.gender').prop('disabled',false);
                },1000);

            }) ;  

I put a setTimeout while the call ends.

Has anyone had a problem like that?

1 Like

Action calling is a Promise function. I would go this route:

        .on('select2:select', function (e) {
        	@this.set('selected',e.params.data.id);
        	@this.call('increment').then((result) => {
                $('.gender').select2();

                $('.gender').prop('disabled',false);
            });
        }) ;