Disable field if a relation manager has records
Let's say I've an order with lines and I want a select field that's in the header to be disabled if the order already has lines. I can just add a:
... and it will work but only when the page is entirely refreshed. It won't behave live as lines are added or removed. How can I achieve that dynamism? Maybe with events?
4 Replies
have you tried with
live
or reactive
method?Yeap, but didn't work. Also tried dispatching events in the relation manager actions that triggered a fillForm when records were modified (added, changed, or deleted) but it didn't work either
Have you tried something like this?
->disabled(fn (Get $get) => count($get('order')) > 0
Or something similar.The issue is that I can't manage to make the disabled closure be executed when lines are changed. I guess there must be a way to execute it with events but I haven't been able to guess how yet
Ok, nevermind. I wasn't properly dispatching the event in the action. Here's a summary on how to make it work:
1. you don't need to make the select reactive nor live,
2. in the after method of your actions in the relation manager, you have to dispatch an event
3. in the EditOrder page, you have to listen the event and call fillForm so the disabled method is executed: