Forum Discussion
dreamweaver
Nov 29, 2019Copper Contributor
WebPart form with JS submit preventDefault
I created a web part and generated a form using Javascript. My objective is to handle the submit event. In the generated form, I have a button : <button id="btnOk" name="btnOk" class="btn btn-pr...
dreamweaver
Nov 29, 2019Copper Contributor
I had to put the
window.addEventListener("submit", handleFormSubmit);
In the method that build the form ...
I had a first eventListener to load the form generated with JS :
window.addEventListener("load", buildForm);
then in buildform() :
const buildForm = () => {
let requestForm = document.createElement('form');
requestForm.setAttribute("class", "form-horizontal");
requestForm.setAttribute("id", "requestForm");
let parentFormDiv = document.getElementById("displayForm");
parentFormDiv.appendChild(requestForm);
... building my stuff ...
/**
* Manage events on form submit : convert the form data in json and send to caml query
*/
formElt.addEventListener("submit", handleFormSubmit);
};