Skip to content

Redraw component from dependsOn function #59

@miagg

Description

@miagg

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions