Extend User plugin backend form in Octobercms

845 Views Asked by At

I extended the user plugin to include extra form fields:

      UsersController::extendFormFields(function ($form, $model, $context) {
       $form->addTabFields([
                'mobile' => [
                    'label' => 'Mobile',
                    'type'  => 'text',
                    'span' => 'storm',
                    'cssClass' => 'col-md-6',
                    'tab' => 'Security Profile'
                ],
                'phone' => [
                    'label' => 'Phone',
                    'type'  => 'text',
                    'span' => 'storm',
                    'cssClass' => 'col-md-6',
                    'tab' => 'Security Profile'
                ],
              ]);
            });

The new fields working fine, but I want to do some javascript functions before saving the form, I searched google and octobercms Javascrip API but no luck.

Please Advice,

1

There are 1 best solutions below

0
On

Add this to your Plugin.php file:

...
use App;
use Event;

class Plugin extends PluginBase
{
    public function boot()
    {
        if (App::runningInBackend()) {
            Event::listen('backend.page.beforeDisplay', function($controller, $action, $params) {
                if (get_class($controller) === 'RainLab\User\Controllers\Users') {
                    $controller->addJs('/your-custom-js/file.js');
                }
            });
        }
    }

    ....
}