【问题标题】:Extend User plugin backend form in Octobercms在 Octobercms 中扩展用户插件后端表单
【发布时间】:2019-04-20 21:16:01
【问题描述】:

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

      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 但没有运气。

请指教,

【问题讨论】:

  • 嗯,如果你能分享你想要做什么样的功能,那么我们可以更好地帮助你:)
  • 是一个普通的JS函数$('#hiddenField').val(JSON.stringify(valueOfExtendedField));,脚本执行后会提交表单
  • 我设法在前端表单中做到这一点,因为我可以完全控制表单,我创建了一个按钮并在点击事件上执行 jQuery,我在事件函数中执行了逻辑并提交表单,它按预期工作。
  • 好的,但似乎在后端您无法控制代码,因此不确定您是否能够处理 hiddenField 值,我知道您想要 create json 并且需要在 backend 中使用它如果您分享您打算如何在后端使用此详细信息,然后我可以帮助您:例如:storing in db table etc..

标签: octobercms octobercms-plugins octobercms-backend


【解决方案1】:

将此添加到您的 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');
                }
            });
        }
    }

    ....
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-01-29
    • 2017-10-26
    • 1970-01-01
    • 2016-04-13
    • 2016-09-25
    • 1970-01-01
    • 1970-01-01
    • 2019-10-24
    相关资源
    最近更新 更多