laravel / nova-issues

557 stars 34 forks source link

4.13.0 appears to break dependsOn (possible regression) #4751

Closed sidawson closed 2 years ago

sidawson commented 2 years ago

Description:

BelongsTo with a Select::make using ->dependsOn worked on 4.12.14. Does not work on 4.13.0

Detailed steps to reproduce the issue on a fresh Nova installation:

  1. Create a nova page, based on a table that has two interdependent fields.

eg,


use App\Models\Customer;
use App\Models\CustomerContract;
use Laravel\Nova\Fields\BelongsTo;
use Laravel\Nova\Fields\FormData;
use Laravel\Nova\Fields\Select;
use Laravel\Nova\Http\Requests\NovaRequest;

BelongsTo::make('Customer'),

// display
BelongsTo::make('Customer Contract', 'customer_contract')
    ->exceptOnForms(),

// edit
Select::make('Customer Contract', 'customer_contract_id')
    ->dependsOn('customer', function(Select $field, NovaRequest $request, FormData $formData) {
        $customer = Customer::whereId($formData->customer ?? $this->customer_id)->first();
        $field->options($customer?->customer_contracts->pluck('description', 'id'));
    })
    ->onlyOnForms(),
  1. Select a Customer (ie, any element from the parent table dropdown)

Expected behaviour (seen only in nova 4.12.14)

When a Customer is selected, the Customer Contract dropdown is limited to contracts owned by that customer

Observed behaviour (seen only in nova 4.13.0)

When a Customer is selected, the Customer Contract dropdown disappears from the screen completely

crynobone commented 2 years ago

Please provide full reproducing repository based on fresh installation as suggested in the bug report template (or you can refer to https://github.com/nova-issues for example)

sidawson commented 2 years ago

Help me out, I've never reported a nova bug before. So I'd need to create:

  1. an empty repo with a clean laravel + nova install (plus all dependencies etc)
  2. migrations - including i) 3 x table creations ii) various test data for each of those tables
  3. configuration necessary for said database (so, user roles, passwords etc etc)
  4. a single nova page with the above 15 lines of code, plus generic boilerplate

I shove all that in a repo somewhere, then add a link here, THEN the above issue can be looked at?

Is that correct?

crynobone commented 2 years ago

Yes, that's correct. We already have multiple dusk tests covering dependent field with BelongsTo and Select which doesn't show any issue as described above. Therefore, it very specific to your use-case that we would need reproducing code in order to verify and debug.

However, you could also make sure you do have the latest assets installed by running php artisan nova:publish.

kusab85 commented 2 years ago

Transferred to https://github.com/laravel/nova-issues/discussions/4774

crynobone commented 2 years ago

Closing this for now, no one else have experience this issue which made it more possible that this is a usage issue and not a bug.

Feel free to submit new issue with reproducing step if anyone have similar issue.