On form submit event
Confluence User - 07 May, 2025
I have a form and I want to make and check some things before the form is sent. So, the obvious way is to create an onsubmit event. I used a script element and a simple test code to cancel the submit:
$(function() { //jquery ready function
const myForm = document.querySelector("#myForm");
myForm.addEventListener("submit", (event)=>{
return false;
});
});
It didn't work. If there are other other statements like alert it will execute them but ignores the return false!
I examined the page code and found that there is already an onsubmit event generated by joget that returns true!
//put it outside the jquery ready function is because the csrf token will be populate correctly when jquery ready.
$("form#myForm").on("submit", function(){
//make sure csrf token is set correctly
var form = this;
if ($(form).find("[name='"+ ConnectionManager.tokenName +"']").length === 0) {
$(form).append('<input type="hidden" name="'+ConnectionManager.tokenName+'" value="'+ConnectionManager.tokenValue+'"/>');
}
return true;
});
Is there a way to handle it;
Many times I have found that Joget has very large limitations on how flexible you can be with what it gives you ready-made, and every time you have to invent some trick at best.
forms;javascript