relationExtendRefreshResults and formRefreshFields

Hi all,

I’m making a custom view for the create and update page for one of my plugins,
Everything was fine, until i wanted to refresh a field when the relationWidget is updated like if a add or remove an item,

i’ve put this in my controller

    public function relationExtendRefreshResults($field)
        // Make sure the field is the expected one

        return $this->formRefreshFields('_total');

But when i add or remove an item in the relation widget, my dependant field is updated just with the last ajax call.

Example :

  1. In my relationwidget i have
    1 x item A = 100 USD
    1 x item B = 100 USD
  1. at this point my total field shows me 200 USD
  1. I remove item A, i expect my total field to refresh with 100 USD value, but the ajax response sends 200 USD
  1. I remove now item B, i expect my total field to refresh with 0 USD value, but the ajax response sends 100 USD

there’s a gap between actions, and i have search in RelationController, and in HasManageMode to fix it, but nothing works,

Could someone help me please ?



UDPATE : i’m using OctoberCMS V2

According to the explanation, the relationExtendRefreshResults($field) is called before the relation widget propagate the removed item. Check the request payload when the refresh event is triggered for depended field.

Thanks for your answer, but i d’ont understand what you’re telling me. There is no refresh event triggered.

@Makgabo, nevermind, i’ve found a solution, and all works great. i will add a response to this to explain how i have fixed this in the next days. thanks again for your help :slight_smile:

1 Like