Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Listeners on generated forms #84

Closed
george-oakling opened this issue Oct 27, 2015 · 2 comments
Closed

Listeners on generated forms #84

george-oakling opened this issue Oct 27, 2015 · 2 comments

Comments

@george-oakling
Copy link

Lets say I have a form, which is generated like below. How could I add listeners for onSuccess on this type of form? Thanks a lot :)

class SpecialForm extends Nette\Object {
   public function create() {
     $form = new UI\Form;
     return $form;
   }
}

class SpecialPresenter {

   /** @inject */
   public $specialForm;

   protected function createComponentSpecialForm() {
      return $this->specialForm->create();
   }
}
@fprochazka
Copy link
Member

Hi, technically, you can. But this lib is not able to autowire events in an instance created like that. You'd have to wire the events by hand

class SpecialForm extends Nette\Object {
   private $evm;
   public function __construct(EventManager $evm) { $this->evm = $evm; }

   public function create() {
     $form = new UI\Form;
     $form->onSuccess = $this->evm->createEvent([get_class($form), 'onSuccess']);
     // ...
     return $form;
   }
}

But your example does not contain a generated form, but rather created by a custom factory. If you really create the form using generated factory, this lib should be able to autowire it.

@george-oakling
Copy link
Author

Thanks a lot, it was much easier to change the logic to standard generated factory and it is working now as expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants