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

Support emit event from Custom Component #443

Merged
merged 1 commit into from
Jan 10, 2020
Merged

Conversation

merobal
Copy link
Collaborator

@merobal merobal commented Jan 10, 2020

This connects the emit event functionality with an Angular component.

Inside the Custom Angular Component, implement as the following:

@Output()
formioEvent = new EventEmitter<FormioEvent>();

And emit an event like:

this.formioEvent.emit({ eventName: 'submitButton', data: { state: 'submitted' } });

This will use the formio emit functionality like:

this.emit('submitButton', {
  state: 'submitted',
  component: this.component
});

The code behind it looks like:

this._customAngularElement.addEventListener('formioEvent', (event: CustomEvent<FormioEvent>) => {
  this.emit(event.detail.eventName, {
    ...event.detail.data,
    component: this.component
  });
});

Note: the formio component class behind the Custom Component is automatically attached.

Closes #434

@travist travist merged commit 181e84e into formio:master Jan 10, 2020
@jftsaraiva
Copy link

@merobal

How can I catch this event?

With this:

<formio [form]='formSrc' [submission]='model' [readOnly]='historyMode' [options]='options'
    (customEvent)="customEvent($event)" ></formio>

I can catch others custom events from, by example, an button.

But it doesn't catch when I emit this:

this.formioEvent.emit({ eventName: 'viewer', data: { url: 'assets/docs/a.pdf' } });

What i'm missing?

@ajaykumarsana
Copy link

ajaykumarsana commented Apr 12, 2022

@jftsaraiva
I've had a similar problem, Did you find any solution?
Please help.

@merobal
this.formioEvent.emit({ eventName: 'viewer', data: { url: 'assets/docs/a.pdf' } });

this event is not getting catch in CustomEvent method
<formio [form]='formSrc' [submission]='model' [options]='options' (customEvent)="customEvent($event)" ></formio>

Please help.
Thanks a Lot.

@alyalin
Copy link

alyalin commented Apr 25, 2022

@jftsaraiva I've had a similar problem, Did you find any solution? Please help.

@merobal this.formioEvent.emit({ eventName: 'viewer', data: { url: 'assets/docs/a.pdf' } });

this event is not getting catch in CustomEvent method <formio [form]='formSrc' [submission]='model' [options]='options' (customEvent)="customEvent($event)" ></formio>

Please help. Thanks a Lot.

Hi. I think (customEvent) firing when you emit it from component with eventName: 'customEvent' and nothing else.

For example:
this.formioEvent.emit({ eventName: 'customEvent', data: { hello: 'world' } });

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

Successfully merging this pull request may close these issues.

How can i trigger a submitButton event in an Angular 8 application with angular elements?
5 participants