Winter CMS resources and help articles

Simple and to the point. Optimized by the community.

How to modify existing form fields?

0
by xyz.qtc, last modified on June 19th, 2022
\Event::listen('backend.form.extendFieldsBefore', function($widget) {
            if ($widget->isNested) {
                return;
            }   

            if ($widget->getController() instanceof Products && $widget->model instanceof Product) {
                $widget->tabs['fields']['additional_descriptions']['form']['fields'] = [
                    'new' => [
                        'type' => 'text',
                        'label' => 'My New Field',
                    ],  
                    'another' => [
                        'type' => 'text',
                        'label' => 'My Other Field',
                    ],  
                ];      
            }

        });

Don't forget to check for $form->isNested in your event handler, otherwise that creates problems with nested form widgets (like repeater and nestedforms)

if ($widget->isNested) {
       return;
}

Discussion

0 comments

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