outl1ne / nova-simple-repeatable

A Laravel Nova simple repeatable rows field.
MIT License
73 stars 42 forks source link

Redraw component from dependsOn function #59

Open miagg opened 5 months ago

miagg commented 5 months ago

Is there any way or even work-around to cause the component to update from within the dependsOn function? Let's say for example that the field is using data from a relationship model that is also selectable on the same resource. Is there a way to do it?

BelongsTo::make('product'),
SimpleRepeatable::make('Varieties', [
    Text::make('name),
    Number::make('percentage'),
])
   ->dependsOn('product', function(SimpleRepeatable $field, NovaRequest $request, Form $formData) {
       $product = Product::find($formData->product);
       $field->setValue($product->varieties->map(fn($p) => $p->only(['name', 'percentage'])->toArray());
       // Does not work :(
       // I also tried the following but does not work either
       $field->withMeta(['rows' => $product->varieties->map(fn($p) => $p->only(['name', 'percentage'])->toArray()]);
    }),

Perhaps it's only there to conditionally display the field?