October CMS resources and help articles

Simple and to the point. Optimized by the community.

Prefill relation widget from main form

0
by Johanness, last modified on November 14th, 2022

To prefill a relationform, we can use the relationManageWidget function in our controller. Conveniently the relationmanagerAjaxCall POSTs the current (not yet saved) form data of the calling form. So we can prefill the popup form like this:

    public function relationExtendManageWidget($widget, $field, $model)
        {                               
                        if($field === 'comments'
                                && property_exists($widget->config, 'context')
                                && $widget->config->context === 'create'
                        ) {
                                $post=Input::get('post');
                                if ($post){
                                        $widget->model->title = 're: '.$post['title'];
                                }
                        }                           
    }

Discussion

0 comments

We use cookies to measure the performance of this website. Do you want to accept these cookies?