Benjacho / belongs-to-many-field-nova

Belongs To Many field Laravel nova to represent many to many relationship in field.
MIT License
157 stars 80 forks source link

While updating data if i change fleet type option and then selected parent category option which is not belongs to fleet type then also can save data without any error. It should not allow to save or if i change fleet type then selected parent category should remove so can select other options which is related to that fleet type. #99

Closed Akanksha-Clarion closed 1 year ago

Akanksha-Clarion commented 2 years ago

What is the solution of this issue? While we change parent option it should remove the child selected options which is not related to parent. And if we save it with different parent and child options which are not belongs to each other data is saved.

I have to clear child selected data from options when we change parent options. What is the solution of this?

        BelongsTo::make('Fleet Type', 'fleetType', FleetType::class)
        ->default(function ($request) {
            if ($request->editMode == 'create') {
                return  self::MEDICAL_FLEET;
            }
        })->withMeta([
            'placeholder' => 'Select Fleet Type',
        ]),

        BelongsToManyField::make(__('Parent Category'), 'parent', Category::class)
        ->dependsOn('fleetType', 'fleet_type_id')
        ->setMultiselectProps([
            'selectLabel' => 'click for select',
            'placeholder' => 'Select Parent Category',
            'openDirection' => 'below',
            'max' => 1
        ])
        ->rules('required'),

What could be the solution that if i select other option of fleet type then selected option of parent category which is not related to that fleet type should remove. So i can select that category which is belongs to fleet type.