Jump to content
  • 0

Can I interrupt a submission when 2 fields have the same data?


HowDoYouWannaDoThis
 Share

Question

10 answers to this question

Recommended Posts

  • 0

You can create a simple formula inside a virtual field that will check if both dates are the same with something like this:

case when [@field:Date1] = [@field:Date2]
then 'ERROR'
else 'GOOD'
end

You can hide this virtual field when testing is done. Next, you need to add a Header and Footer and add the following JavaSrcipt code at the Header:

<script type="text/javascript">

document.addEventListener('BeforeFormSubmit', function(event) {

var Input1 = document.querySelector("span[id^='cbParamVirtual1']").innerHTML

if (Input1 === 'ERROR') {
event.preventDefault();
alert('Your Dates have the same value');

});
</script>

Make sure to disable HTML editor and replace cbParamVirtual1 with the respective virtualfield name ex. If you're using Virtual3 for this formula then it should be cbParamVirtual3.

You can also edit the alert to display any message you want. The "event.preventDefault();" will prevent submission of the current input.

 

 

 

Link to comment
Share on other sites

  • 0

A question to you @Wikiwi: Would you have the same script for a details page, I have exactly the same use case when user makes changes

I have this formula in a Virtual field (virtual6):

CASE WHEN [@cbParamVirtual5] = 1 THEN 'GOOD' ELSE 'ERROR' END

And this script you provided, that works fine in Forms, but not in my Report Details page:

<script type="text/javascript">

document.addEventListener('BeforeFormSubmit', function(event) {

var Input1 = document.querySelector("span[id^='cbParamVirtual6']").innerHTML

if (Input1 === 'ERROR') {
event.preventDefault();
alert('Message to user');

});
</script>

Link to comment
Share on other sites

  • 0
On 2/14/2022 at 7:51 AM, Gunnar360c said:

A question to you @Wikiwi: Would you have the same script for a details page, I have exactly the same use case when user makes changes

I have this formula in a Virtual field (virtual6):

CASE WHEN [@cbParamVirtual5] = 1 THEN 'GOOD' ELSE 'ERROR' END

And this script you provided, that works fine in Forms, but not in my Report Details page:

<script type="text/javascript">

document.addEventListener('BeforeFormSubmit', function(event) {

var Input1 = document.querySelector("span[id^='cbParamVirtual6']").innerHTML

if (Input1 === 'ERROR') {
event.preventDefault();
alert('Message to user');

});
</script>

I tried the script (my configuration and yours) on a Details Page and it should worked just fine. If you're having issues with it, maybe you should put the script in the footer and not the header. But I tried both configurations on my end and I haven't encountered any errors.

Link to comment
Share on other sites

  • 0
2 hours ago, Wikiwi said:

I tried the script (my configuration and yours) on a Details Page and it should worked just fine. If you're having issues with it, maybe you should put the script in the footer and not the header. But I tried both configurations on my end and I haven't encountered any errors.

Thanks @Wikiwi, I tested again and here is what's going on: The Report and Details page is on the same web page as a Submission From with that exact same script, so I tried two things:

  1. Deployed the Report on another web page – it works perfectly fine
  2. Changed the script a bit referencing different fields and values - The same issue remains, the Form works fine but not the Report details page

I suppose they might interfere with one another, and I might have to place the Form and the Report on different web pages, although quite nice to have them side by side.  

Additional ideas welcome,

G

Link to comment
Share on other sites

  • 0

I would like to add one remark to the topic of blocking submission of a form upon undesirable input data.

On 2/15/2022 at 5:53 PM, Wikiwi said:

I tried the script (my configuration and yours) on a Details Page and it should work just fine. If you're having issues with it, maybe you should put the script in the footer and not the header. But I tried both configurations on my end and I haven't encountered any errors.

I struggled to get this script working in several cases. The mistake I made was upper- and lowercase errors. The formula presented by @Wikiwiworks fine if one implements it precisely as presented. I stated *Error' instead of 'ERROR' because I did not know that the script was case sensitive.

Hate for others to waste the same amount of time as I did, until I had Alex from Caspio Support analyze the script and come to the conclusion I had the wrong upper/lower case combination. Thank you @Wikiwi for the formula and Caspio Support for setting me on the right course here. The script is essential to make a better user experience and accuracy of input data!

G

Link to comment
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
Answer this question...

×   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...
 Share

×
×
  • Create New...