0

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,

Ya Basha
  • 1,902
  • 6
  • 30
  • 54
  • hmm if you can share what kind of functions you want to do then we can help you better :) – Hardik Satasiya Nov 19 '18 at 06:40
  • 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 Nov 19 '18 at 21:30
  • 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 Nov 19 '18 at 21:31
  • 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 Nov 20 '18 at 10:56

1 Answers1

2

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

    ....
}
Joseph Oppegaard
  • 611
  • 5
  • 12