laravel / nova-issues

554 stars 34 forks source link

BelongsTo doesn't trigger `dependsOn` on value changes #4773

Closed crynobone closed 2 years ago

crynobone commented 2 years ago

Open Posts page and edit a Post. Callback function is called only once when page is being loaded. After that, changing value of the User field does not do a thing. Just look into laravel.log

Cheers!

UPDATE: It seems that dependsOn doesn't work at all, no matter what field uses it. Check 'Post With Dependencies' page in my TestApp

Originally posted by @kusab85 in https://github.com/laravel/nova-issues/issues/4751#issuecomment-1234355775

crynobone commented 2 years ago

@kusab85 I don't understand why you code it as below:

Text::make('Title')
                ->rules('required')
                ->dependsOn(['user'],
                    function (Text $field, NovaRequest $request, FormData $formData) {
                        logger(get_class($this).": User changed to ".var_export($formData->user, true));
                    }
                )
                ->dependsOn(['status'],
                    function (Text $field, NovaRequest $request, FormData $formData) {
                        logger(get_class($this).": Status changed to ".var_export($formData->status, true));
                    }
                )
                ->dependsOn(['created_at'],
                    function (Text $field, NovaRequest $request, FormData $formData) {
                        logger(get_class($this).": Created at changed to ".var_export($formData->created_at, true));
                    }
                ),

If Title depends on user, status and created_at it should be ->dependsOn(['user', 'status', 'created_at'], ...)

crynobone commented 2 years ago
Text::make('Title')
                ->rules('required')
                ->dependsOn(['user', 'status', 'created_at'],
                    function (Text $field, NovaRequest $request, FormData $formData) {
                        ray(get_class($this).": User changed to ".var_export($formData->user, true));
                        ray(get_class($this).": Status changed to ".var_export($formData->status, true));
                        ray(get_class($this).": Created at changed to ".var_export($formData->created_at, true));
                    }
                ),

CleanShot 2022-09-02 at 09 33 01