[Question] how to append a button inside default modal and catch it's click event
See original GitHub issueI 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 :
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.
`const domc = editor.DomComponents;
const defaultType = domc.getType('default');
domc.addType("test-type", {
model: defaultModel.extend(
{
defaults: Object.assign({}, defaultModel.prototype.defaults, {
type : "test-type",
id:"popup",
droppable : false,
resizable : true,
tagName:"popup",
}),
getAttrToHTML: function() {
var attr = defaultType.model.prototype.getAttrToHTML.apply(this, arguments);
delete attr.onmousedown;
var testmarker = this.get("testmarker");
if(testmarker)
attr.testmarker = testmarker;
return attr;
}
}),
view: defaultType.view.extend({
tagName: "button",
events: {
"dblclick": "openModal",
},
initialize: function(o) {
defaultType.view.prototype.initialize.apply(this, arguments);
this.listenTo(this.model, "change:testmarker", this.updateMarker);
this.listenTo(this.model, "dblclick active", this.openModal);
},
updateMarker: function() {
var testmarker = this.model.get("testmarker");
this.$el.attr("testmarker", testmarker);
},
openModal: function(e) {
const modal = editor.Modal;
modal.open({
title: '<br>Create Identity<br>',
content: `
<div class="container">
<br>
<form onsubmit="formSubmit()">
<div class="form-group">
<label>URL</label>
<input type="text" class="form-control" id="url" placeholder="http://test-data/" name="url">
</div>
<br>
<div class="form-group">
<label>Identity </label>
<input type="text" class="form-control" id="address" placeholder="Enter Identity Address" name="address">
</div>
<br>
<button type="submit" class="btn btn-danger">Submit</button>
</form>
<br>
</div>`,
});
},
})
});`
Is my approach correct? Should I do it in a different way ?
Issue Analytics
- State:
- Created 4 years ago
- Comments:8 (1 by maintainers)
Top Results From Across the Web
Appended Element Inside show.bs.modal didn't Get ...
What I want is that the .append to got overwritten everytime the modal button is clicked(Just like the first click picture). If I...
Read more >Modal
Use Bootstrap's JavaScript modal plugin to add dialogs to your site for lightboxes, user notifications, or completely custom content.
Read more >The Dialog element - HTML: HyperText Markup Language
This example opens a modal dialog when the "Show the dialog" button is activated. The dialog contains a form. Updating the value of...
Read more >How to pass data into a bootstrap modal?
Example 2: In this approach, a textarea is used to take input from the user. When the submit button is clicked, it invokes...
Read more >Handling Events
Giving a node an onclick attribute has a similar effect. This works for most types of events—you can attach a handler through the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Doing away with the form and just using javascript to create/interface with the modal contents works well.
modal.setContent()
for appending the button andmyButton.onclick = () => {}
to catch its click event. Here’s some example code:@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 😃