Issue #2129✓ SolvedOpened July 11, 2019by nikitha1216 reactions

How to append a button inside default modal and catch it's click event

Quick answerby giorgiosjames12

Doing away with the form and just using javascript to create/interface with the modal contents works well. modal.setContent() for appending the button and myButton.onclick = () => {} to catch its click event. Here's some example code:

Read full answer below ↓

Question

I want a form inside a modal (using the default modal ), on click of the submit button make an ajax call. I have created a new component which pops a modal on drag and drop. I am able to insert the form in the modal It looks like this : <img width="1001" alt="Screen Shot 2019-07-11 at 10 22 17 AM" src="https://user-images.githubusercontent.com/36627122/61023023-cf1a4180-a3c5-11e9-8fcb-3da790ff9d61.png">but I don't know how to track the submit button click. I tried writing OnSubmit() in a Script and added to the modal content, its not working. Is my approach correct? Should I do it in a differ...

Answers (3)

👍 Most helpfulgiorgiosjamesJuly 12, 2019

Doing away with the form and just using javascript to create/interface with the modal contents works well. modal.setContent() for appending the button and myButton.onclick = () => {} to catch its click event. Here's some example code:

artfJuly 14, 2019

The point here is that content accepts HTML nodes (not only HTML strings) so you can have any HTMLElement with any attached event (forms with submits, buttons with clicks, etc.) so the approach proposed is totally valid (thanks @giorgiosjames)

Related Questions and Answers

Continue research with similar issue discussions.

Paid Plugins That Match This Issue

Curated by issue keywords and label relevance to help you ship faster.

View all plugins

Loading paid plugin recommendations...

Free option

Check the open-source GrapesJS plugins on GitHub or run a quick search in our free catalog.

Browse free plugins →
Premium option

Premium plugins ship with support, regular updates, and production-ready features — save days of integration work.

Browse premium plugins →

Browse Plugin Categories

Jump directly to plugin category pages on the marketplace.