This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

Eoler
Eoler

Ciao, I'd like to autogenerate some values for existing backend form fields according to client's business rules (think random strong passwords).

I tried with extendFormFields but it is not working (too late?) - pseudo code:

        ForeignController::extendFormFields(function($form, $model, $context) {
            if (!$model instanceof ForeignModel) return;
            if ($context == 'create') {
                $form->getField('foreignfield')->defaults = "...";
                $form->getField('foreignfield')->config['default'] = "...";
            }
        });

Any ideas?

alxy
alxy

I'd rather set the values on the model, to which you have also access to in the named function ;) $model->attribute = 'default';

Eoler
Eoler

alxy said: I'd rather set the values on the model

Nope, doesn't work inside my plugin boot():

        UsersController::extendFormFields(function($form, $model, $context)
        {
            if (!$model instanceof UserModel) return;

            if ($context == 'create')
            {
                $model->name = "...";
                $model->email = "...@...";
                //dd($model);
            }
        });

1-3 of 3

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.