Dependent Fields in Laravel Nova not working with Repeater Fields #5669
-
Description: The Dependent Fields functionality in Laravel Nova is not working properly when used in conjunction with the recently added Repeater Fields. Code Snippet: /**
* Get the fields displayed by the repeatable.
*
* @param \Laravel\Nova\Http\Requests\NovaRequest $request
* @return array
*/
public function fields(NovaRequest $request)
{
return [
Select::make(__('attribute.singular'), 'attribute')
->options(Attribute::all()->pluck('name', 'id')->toArray())
->displayUsingLabels()
->searchable(),
Select::make(__('attribute_value.singular'), 'attribute_value')
->hide()
->rules('sometimes')
->dependsOn('attribute', function ($field, NovaRequest $request, $formData) {
$field->readonly();
$attributeId = (string) $formData->resource(\App\Nova\Attribute::uriKey(), $formData->attribute);
if ($attributeId) {
$values = \App\Models\AttributeValue::where(['attribute_id' => $attributeId])->pluck('value', 'id')->toArray();
$field->options($values)->rules('required')->show()->readonly(false);
return;
}
})
->displayUsingLabels()
->searchable(),
];
} Issue Details: Steps to Reproduce:
Please let me know if you need any further information or clarification. |
Beta Was this translation helpful? Give feedback.
Replies: 10 comments 4 replies
-
Code insile Repeater::make(__('attribute_value.plural'), 'attribute_values', AttributeValue::class)
->repeatables([
AttributeValueItem::make(),
])
->asJson(), |
Beta Was this translation helpful? Give feedback.
-
Unfortunately, it's not (yet?) supported: https://nova.laravel.com/docs/4.0/resources/repeater-fields.html#repeater-field-capabilities |
Beta Was this translation helpful? Give feedback.
-
Is there an ETA for dependsOn with Repeatable fields? or any workaround. |
Beta Was this translation helpful? Give feedback.
-
Could we have the repeatable field itself to be compatible with dependsOn as they are on the same form and same level? For context I'm building a form builder resource, and would like to show the repeatable field based on the value of a select on the same form. public function fields(NovaRequest $request)
{
return [
Select::make('Type')
->options(FormFieldType::dropdownOptions())
->displayUsingLabels()
->required(),
Repeater::make('Options')
->dependsOn('type', FormFieldType::SELECT) // this function doesn't exist
->repeatables([
SelectOption::make(),
])
->asJson(),
];
} |
Beta Was this translation helpful? Give feedback.
-
We really need this feature besides nested repeatable |
Beta Was this translation helpful? Give feedback.
-
+1 I think it is a very necessary functionality |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
Would this be on the roadmap? Even just the ability to hide the Repeater field itself based on the value of another field? |
Beta Was this translation helpful? Give feedback.
Unfortunately, it's not (yet?) supported:
Also, fields inside a Repeatable do not support dependent field (dependsOn) functionality.
https://nova.laravel.com/docs/4.0/resources/repeater-fields.html#repeater-field-capabilities