Sep 12, 2022
0
Level 7
Field value based on relationship
I am trying to make some readonly fields that their values are populated by a relationship value the admin selects. So in short, when they create a new order the "email" field for the order is readonly and will fill out on based upon the "retailer" they select to save time.
I tried this but its not working
BelongsTo::make('Retailer', 'retailer', Retailer::class)
->sortable(),
Text::make('Name')
->dependsOn(
['retailer'],
function (Text $field, NovaRequest $request, FormData $formData) {
$retailer = $formData->resource(Retailer::uriKey());
$field->value = $retailer->name;
}
)
->readonly(),
Please or to participate in this conversation.