在Octobercms中扩展用户插件后端表单

时间:2018-11-18 07:58:53

标签: octobercms octobercms-plugins octobercms-backend

我扩展了用户插件以包括额外的表单字段:

      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'
                ],
              ]);
            });

新字段工作正常,但是我想在保存表单之前执行一些javascript函数,我搜索了google和octobercms Javascrip API,但是没有运气。

请咨询

1 个答案:

答案 0 :(得分:2)

将此添加到您的Plugin.php文件中:

...
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');
                }
            });
        }
    }

    ....
}