laravel / nova-issues

557 stars 34 forks source link

BelongsTo + dependsOn + relatableQueryUsing not refreshing on Update #5083

Closed jonrmitchell closed 2 years ago

jonrmitchell commented 2 years ago

Description:

The new BelongsTo + dependsOn + relatableQueryUsing feature is fantastic! But it won't refresh the dependant field's belongsTo options when Updating resources. It works fine when Creating, just not when Updating.

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

Create 3 models (User, Account, and Document) User belongsTo Account Document belongsTo User and Document belongsTo Account On the Document resource, make the Document's User dependOn the Document's Account Create 2 Accounts Create 2 users, each with a different account Create a Document that belongs to one Account (the dependsOn will filter the available user automatically) Save the Document Edit the Document Change the Account

Expected result: the available Users should repopulate, only allowing the other user to be selected. Actual result: the available Users don't repopulate

jonrmitchell commented 2 years ago

I did some source diving and I believe this is because the onSyncedField() method of BelongsToField.vue returns early if you're editing an existing resource, so it never calls this.initializeComponent() and the dependent field never refreshes its available resources.

//resources/js/fields/Form/BelongsToField.vue
onSyncedField() {
      if (this.editingExistingResource || this.creatingViaRelatedResource) {
        return
      }

Using the browser debugger, if I pause just inside onSyncedField() and manually execute a this.initalizeComponent() then it does refresh the dependent field available resources.

github-actions[bot] commented 1 year ago

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.