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

BelongsTo with dependsOn shows every resource even though is hidden #6412

Closed
ecreeth opened this issue May 29, 2024 · 2 comments
Closed

BelongsTo with dependsOn shows every resource even though is hidden #6412

ecreeth opened this issue May 29, 2024 · 2 comments
Labels
bug Verified bug by the Nova team
Milestone

Comments

@ecreeth
Copy link

ecreeth commented May 29, 2024

  • Laravel Version: ^11.0
  • Nova Version: ^4.34
  • PHP Version: 8.3.2
  • Database Driver & Version: SQlite
  • Operating System and Version: Windows 10
  • Browser type and version: Edge
  • Reproduction Repository: https://github.com/ecreeth/nova-belogns-to-bug

Description:

As shown in the following video, when you have a BelongsTo field and you have another that depends on it, the second BelongsTo will show all the resources regardless of whether it is hidden.

In the video you can notice that the country field has all the available countries by default. This is a problem since if you have a large list (in this case of countries) Nova will show all the resources.

bug-report.mp4
@ecreeth
Copy link
Author

ecreeth commented May 29, 2024

What's the expected behavior of a BelongsTo field that dependsOn another field and is hidden?
It should remain empty until specified.

EJ:

BelongsTo::make('Country'),

BelongsTo::make('City')
    ->hide()
    ->dependsOn('country', function (BelongsTo $field, NovaRequest $request, FormData $formData) {
        if ($formData->country) {
            $field->relatableQueryUsing(fn (NovaRequest $request, Builder $query) =>
            $query->where('country_id', $formData->country));
        } else {
            $field->hide();
        }
    }),

The City field should only show cities when a country is selected. But, right now it shows all cities. You can confirm this in the debug-bar too.

@ecreeth ecreeth changed the title BelongsTo with dependsOn doesn't respect relatableQueryUsing BelongsTo with dependsOn shows every resource even though is hidden May 29, 2024
@crynobone crynobone added the bug Verified bug by the Nova team label Jun 1, 2024
@crynobone crynobone added this to the 4.x milestone Jun 1, 2024
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 18, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Verified bug by the Nova team
Projects
None yet
Development

No branches or pull requests

2 participants