Closed RomkaLTU closed 1 year ago
Is it really nothing more than what is in #50 ? can you try that branch out? feature-supports-dependent-fields
edit: tagging @RomkaLTU
It doesn't work for me.
When i create field like this:
SelectPlus::make('Checklists', 'checklists', Checklist::class)->dependsOn('tenant_id', function ($field, NovaRequest $request, FormData $formData) { if ($formData['tenant_id']) { dd($formData); } }),
And change tenant_id field, dependsOn doesn't want to be triggered.
If SelectPlus change with simple nova Select field type then it is triggered and works as it should.
Maybe you must replace this in mixin and vue template https://nova.laravel.com/docs/4.0/customization/fields.html#dependent-form-field
Me too. It seems there is no dependsOn support.
Please try v2.0.2 and report back. Thanks!
Please try v2.0.2 and report back. Thanks!
@ralphschindler is it possible to publish it on packagist?
Try now, had to update the webhook settings.
@ralphschindler I just tried v2.0.2.
Sadly it does not work for me 😥
Here is my field for reference
SelectPlus::make('Product Varieties', 'productVarieties', ProductVariety::class)
->usingDetailLabel('name')
->resolveUsing(fn($models) => $models->sortBy('pivot.order')->values())
->reorderable('order')
->required()
->onlyOnForms()
->dependsOn('productType', function (SelectPlus $field, NovaRequest $request, FormData $formData) {
if (!$formData->productType) {
return;
}
$field->optionsQuery(
fn(Builder $query) => $query->where('product_type_id', $formData->productType)
);
})
The callback is indeed triggered on every update of productType field (tested with ray) but any changes to the field are not reflected.
oh wow. that is much trickier. in that particular case, the controller also need to know about the dependsOn state, and needs to be able to re-setup the initial options values (if it is not autocomplete).
I will take a stab at this.
Please try v2.0.3-beta.1
it is built off the fix-dependson-in-controller
branch
Please try
v2.0.3-beta.1
it is built off thefix-dependson-in-controller
branch
Yes! It works! 👏
It has been released as v2.0.3
and I removed that beta tag/release.
But still some native field options don't work, for example:
SelectPlus::make('Product Varieties', 'productVarieties', ProductVariety::class)
->usingDetailLabel('name')
->resolveUsing(fn($models) => $models->sortBy('pivot.order')->values())
->reorderable('order')
->required()
->onlyOnForms()
->dependsOn('productType', function (SelectPlus $field, NovaRequest $request, FormData $formData) {
if (!$formData->productType) {
$field->show();
} else {
$field->hide();
}
})
I would like to be able to add for example: ->required()
or disable it depending on the other field.
On all others basic Nova Fields all this methods work as they should.
Would be nice to have ->dependsOn() support.