This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

mitch
mitch

Hello,

is there a way to dynamically change the modelClass property on the RecordFinder widget?

Thanks.

mjauvin
mjauvin

it's a public property of the object, so you should be able to change it.

mjauvin
mjauvin
mjauvin
Event::listen('backend.form.extendFieldsBefore', function ($widget) {
    // make sure you have the right model & controller here...
    if ($widget->getController() instanceof yourController  && $widget->model instanceof yourModel) {
        $widget->fields['recordFinder_fieldName']['modelClass'] = 'otherClass';
    }
});
mitch
mitch

Thank you. It works in the 'backend.form.extendFieldsBefore' event. When I try the same in the 'backend.form.refreshFields' event, the new modelClass is not used.

I use the 'backend.form.refreshFields' event because RecordFinder dependsOn some other field.

mjauvin
mjauvin

But if you set it using backend.form.extendFieldsBefore it should still have the same value when you do your things using backend.form.refreshFields?!

mjauvin
mjauvin

I verified the code flow in the source code and backend.form.extendFieldsBefore is definitely going to be fired within onRefresh() BEFORE the backend.form.refreshFields event is fired.

mitch
mitch

All good. It works as it should. Thank you.

1-8 of 8

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.