jhorngacher's avatar

jhorngacher was awarded Best Answer+1000 XP

5mos ago

After a lot of debugging i couldn't really figure out why the $stopPropagation() doesn't stop the Form Property from being updated. Maybe it's because I am using wire:model.live?

Anyway I decided to move along and use a temporary property to reset the updated property if the auth check failed

jhorngacher's avatar

jhorngacher wrote a reply+100 XP

5mos ago

After a lot of debugging i couldn't really figure out why the $stopPropagation() doesn't stop the Form Property from being updated. Maybe it's because I am using wire:model.live?

Anyway I decided to move along and use a temporary property to reset the updated property if the auth check failed

jhorngacher's avatar

jhorngacher wrote a reply+100 XP

5mos ago

I had this solution already implemented, but somehow the property value is still getting changed.

 public function exceptionHandlesFormPermission($e, $stopPropagation){
        if($e instanceof Exception){
            $this->dispatch('notification.add', [
                'type' => 'error',
                'message' => $e->getMessage(),
            ]);
            $stopPropagation();
        }

    }
jhorngacher's avatar

jhorngacher wrote a reply+100 XP

5mos ago

Alright, thanks for the helpful tips on the best practices.

Further the issue still persists since your provided solution also throws an exception. The exception was thrown already before and I even get the error message on the client side. Still my variable gets changed. And I don't know why since Livewire docs also state that throwing an exception in updating is enough ..

jhorngacher's avatar

jhorngacher started a new conversation+100 XP

5mos ago

I am pretty new to the Livewire ecosystem and trying to figure out the following thing.

So I have a component which uses a Trait to determine if a user can perform the updating method on a specific variable. So far so good, the check is working fine by using the updating{Trait} hook. The method throws an exception as I expect it. So I am going to use another hook exception{Trait}. The exception method gets called, a unique message gets dispatched. Now my issue, how am I able to prevent the property from being updated? When i check the request debug it updates the property inside my component. Here's my current used code


   class CustomComponent {

       use CheckFormPropertyPermissions;
	    
        // shouldnt get updated with the updating hook?
        #[HasPermission('someperm')]
        public int|null $someId = null; 


}

Maybe someone is able to give me a hint?

Thanks in advance