Adam
Adam

I have a backend form where one of the text inputs is dependent on another field. Using the depends option in fields.yaml I can see that the form::onRefresh funciton is used to send the form data, and the field that has the depndency. What I can't figure out is how to access that from my plugin controller - I need to do some custom bits and bobs and return something to the text input.

I've tried using an index_onRefresh() function as we use index_onDelete() but that doesn't seem to kick in.

The RainLab users plugin uses the depends field on the state dropdown. This is handled in the model using the getFieldOptions() function - I'm using a text input so can't use this. The only thing I can think of doing at the moment is to create a widget and use that instead of the text input and just catch the post. Gut says that's probably not the best way?

Cheers,

Adam

Adam
Adam

Oops posted in wrong forum - can mod move please?

demagu
demagu

Hi Adam,

Did you figure this out? Looking for something similar.....

Adam
Adam

I ended up creating a widget. When a field depends on another field OctoberCMS does an ajax post, so I caught that in widget render() function, checked it was posting the right fields and then did what I required and then returned the widget partial.

KurtJensen
KurtJensen

Are you willing to share your discovery? I am struggling through same process.

Adam
Adam

Ok registering and creating a widget is all covered here: https://octobercms.com/docs/backend/widgets

In my render function I then checked the if the post variable I wanted existed and then did my bits before returning the partial.

public function render()

{
    if(post('post_variable'))
    {

      // Logic here

  }
    return $this->makePartial('partial');
}

Last updated

Adam
Adam

I did find that I had two have two fields declared in the corresponding fields.yaml - one the widget and one a hidden field. When something was selected in widget field it updates the hidden field with the value. This probably isn't required but I could work out how to get / post the value of anything in the widget.

Adam
Adam
field_1:
      label: Field 1
      span: left
      hidden: true
widget_field:
     label: Widget Field
     type: Parth\To\Widget\File
     span: left
     depends: field_it_depends_on
     required: true

Last updated

1-8 of 8