Jump to content
Sign in to follow this  
Elderberg

Update Form via javascript

Recommended Posts

Hi, See below the code which i've used on a web form submission successfully.  I've tested this on the Details page, it seems to work, however, the changes made on the Details page don't get written to the database table.

Any advise welcome..

<script>

// PREVENT SUBMIT UNLESS VALIDATED
document.addEventListener('BeforeFormSubmit', function(event) {
event.preventDefault();

//do something before submitting update

document.forms["caspioform"].submit();

});
</script>

 

Share this post


Link to post
Share on other sites

I've isolated the issue to when i have 2 data pages.. with the update page being the second one.  I think the document.forms["caspioform"].submit()  is submitting the first datapage (which is a HTML page).

Any ideas.

Share this post


Link to post
Share on other sites

Did some reading and testing..  my solution, isn't perfect, it just submits the last form on a page with multiple forms.  Note that this counts ALL forms and not just forms with "caspioform" as the ID.

 

var x = document.forms;
x[x.length-1].submit();

 

Share this post


Link to post
Share on other sites

Hi @Elderberg,

I would like to share a different approach, so instead of using a submit() function I have used the click() function on Submit button to mimic submit event.

Also, it is possible to use AppKey of the Datapage in order to submit the particular Datapage if more than one is deployed.

<script type="text/javascript">
document.addEventListener('BeforeFormSubmit', function (event) {
  
if (event.detail.appKey == 'XXXXXXXXXXXX') { 
  
event.preventDefault();  
  
//do smth before Submit
  
document.querySelector(`#Submit${event.detail.uniqueSuffix}`).click();
  
}

});
</script>

Hope it helps.

Regards,

vitaliksssss

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...