Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redraw component from dependsOn function #59

Open
miagg opened this issue Apr 1, 2024 · 0 comments
Open

Redraw component from dependsOn function #59

miagg opened this issue Apr 1, 2024 · 0 comments

Comments

@miagg
Copy link
Contributor

miagg commented Apr 1, 2024

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant