Default value for multiple select field. But it needs to be hidden
Hi together,
I have the models Company and CompanyType which are linked via the pivot model CompanyHasCompanyTypes.
So in the EditPage I have set up this SelectField:
And it works. I can select the company types and they are saved correctly.
Now there is a condition, that depending which user is logged in and depending on the user roles they have, some fields are shown and some are not. CompanyTypes is one of them. What I need to do now, is to still provide a default value without displaying the field.
I have tried this first:
but that didn't do it. Is there a possibility to achieve the desired behaviour?
Solution:Jump to solution
Use the
mutateDateBeforeCreate()
/mutateDateBeforeSave()
to fill in the data based on the role instead.8 Replies
Solution
Use the
mutateDateBeforeCreate()
/mutateDateBeforeSave()
to fill in the data based on the role instead.Yeah that's my workaround for now too. Just thought there might be a cleaner solution 🙂
Nope, that's the best solution
Gotcha. Thank you very much🙏
@Dennis Koch Okay follow up question: for some reason, for the displayed select field, the data is not shown inside
$data
of mutateFormDataBeforeSave()
. Any idea why? It does get saved correctly thoughIt’s because relationships are saved directly. Sorry I missed that. But it shouldn’t matter for the case where you want to pass a default.
Ah I see. Yes it shouldn't matter, was just confused
Yeah. That was more reassurance for myself 😅