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

When a BelongsToManyField 'depends on' another field, if the parent field is updated, the values unmatch. #3300

Closed
Vaishonline opened this issue Mar 22, 2021 · 1 comment

Comments

@Vaishonline
Copy link

  • Laravel Version: 8.0
  • Nova Version: 3.12.0
  • PHP Version: 7.4.9
  • Operating System and Version: Windows10
  • Browser type and version: Chrome 89

Description:

image
image

BelongsToManyField::make('Questions','questions', 'App\Nova\Question')
->optionsLabel('title')
->showOnUpdating(true)
->dependsOn('class_subject','class_subject_id')

Note that the objects in the BelongsToManyField get filtered based on the value in the field above it.
When I update my parent field (in this case Class Subject) to something else, it is allowing me to save the updations even though the selected objects in the BelongsToManyField don't match the parent field anymore (Class Subject).

Is it possible to clear the selected objects in the BelongsToManyField if the parent field is updated?

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

Install the package BelongsToManyField using the command:
composer require benjacho/belongs-to-many-field

Create a resource with the code shown below:

        BelongsTo::make('Class Subject','class_subject')->showOnUpdating(true),

        BelongsToManyField::make('Questions','questions', 'App\Nova\Question')
            ->optionsLabel('title')
            ->showOnUpdating(true)
            ->dependsOn('class_subject','class_subject_id')
            ->canSelectAll('Select All')
            ->showAsListInDetail()
            ->hideFromIndex()

When I update the value in Class Subject, even if I don't reselect the Questions, it allows me to update and save the changes. In this case, the relationship is violated as the Questions will not belong to the updated Class Subject.

Benjacho/belongs-to-many-field-nova#75 (comment)

@crynobone
Copy link
Member

crynobone commented Mar 22, 2021

I think this should be discussed in the responding package.

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

2 participants