0
votes

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
hmm if you can share what kind of functions you want to do then we can help you better :) - Hardik Satasiya
it is a normal JS function $('#hiddenField').val(JSON.stringify(valueOfExtendedField)); and after the execution of the script it will submit the formm - Ya Basha
I managed to do that in a frontend form as I have full control over the form, I created a button and did jQuery on click event and I did the logic inside the event function and submit the form, it worked as expected. - Ya Basha
ok but seems in backend you can not control over code so not sure you are able to process hiddenField value, I understand you want to create json and need to use it in backend if you share how you intend to use this details in backend then I can help you : for ex like: storing in db table etc.. - Hardik Satasiya

1 Answers

2
votes

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

    ....
}