Can't get the field when disabled
I have made the employee_id selectable for role-based users. However, when the field is disabled, I can't get the employee_id in $data inside the handleRecordCreation().
Solution:Jump to solution
As noted you need to have disabled before dehydrated ie:
I use this combo all the time...
12 Replies
That's because the field is disabled. Try making it readonly or hidden. Browsers don't submit disabled fields.
That's a Select field and Select::readOnly does not exist.
You should add additional hidden field with employee_id value.
Thanks for your suggestion. I have tried this also but it act same like as disabled.
If the field was hidden also can't get that inside $data.
If it doesn’t change then you don’t need it in $data. It still exists on the $record and can be retrieved from there.
Yeah actually i have not change the field and it was required field in my table.
At the time of record creation that employee_id key was not there so it's returning error.
You can inject $operation into the callback for things like required() and disabled() to make it required on create and not on edit.
https://filamentphp.com/docs/3.x/forms/advanced#injecting-the-current-form-operation
if a field is disabled and you still want the data use
->dehydrated()
i have tried this also doesn't work.
Here is my code snippet looks like
disabled before dehydrated
Solution
As noted you need to have disabled before dehydrated ie:
I use this combo all the time
Thanks @Hussain4real and @DariusIII .
It's working fine.