How to append a button inside default modal and catch it's click event
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)
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:
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)
@giorgiosjames Thanks, man this(https://github.com/artf/grapesjs/issues/2129#issuecomment-510734779) is work like a charm in my case.
Your answer save a lot of my time :)
Related Questions and Answers
Continue research with similar issue discussions.
Issue #3239
[Question] How to update attribute/properties dynamically from Component Script?
We have a use case where we want to insert charts dynamically using Highcharts Editor. I have created a component, which on drag and drop,...
Issue #3135
[Help Wanted] How to easily override existing component ?
For example, I want to add a double click event handler on the default video component to open the assets manager. My basic idea was to get...
Issue #3422
How we can remove default text content from text component 'Insert your text here' ?
I want to remove default text from text component just like placeholder. every time when we drag text component we need to remove default t...
Issue #6683
Modals close on mouseup event outside of modal rather than a full click
GrapesJS version [x] I confirm to use the latest version of GrapesJS What browser are you using? Chrome 143.0.7499.169 Reproducible demo li...
Paid Plugins That Match This Issue
Curated by issue keywords and label relevance to help you ship faster.
Loading paid plugin recommendations...
Check the open-source GrapesJS plugins on GitHub or run a quick search in our free catalog.
Browse free plugins →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.