Jump to content

Don't Allow Prior Dates on Submission Form


Recommended Posts

I have a submission form that I need to not allow users from submitting the form with an date that is prior to the current month.  Also I only want to block this on or after the 5th of each month.  So for example if it is 06/02/2021, they can submit the form with a prior date.  But if it is 06/05/2021 or after for example, then they can only submit the form with a date of 06/01/2021 or after.   I am already using multiple rules to display other messages and block the Submit button but I think I am at the point where some rules are conflicting with others.  So I thought some Java script might be able to handle this better.  I am a copy and paste type of java script person so I very much appreciate anyone's talent that can provide code to do this.  I'm fairly good at tweaking the code once the main functionality is there.

Link to post
Share on other sites
18 hours ago, jimarch said:

I have a submission form that I need to not allow users from submitting the form with an date that is prior to the current month.  Also I only want to block this on or after the 5th of each month.  So for example if it is 06/02/2021, they can submit the form with a prior date.  But if it is 06/05/2021 or after for example, then they can only submit the form with a date of 06/01/2021 or after.   I am already using multiple rules to display other messages and block the Submit button but I think I am at the point where some rules are conflicting with others.  So I thought some Java script might be able to handle this better.  I am a copy and paste type of java script person so I very much appreciate anyone's talent that can provide code to do this.  I'm fairly good at tweaking the code once the main functionality is there.

Not sure if what I understood is correct, but, you can try this, create a Calculated Value, this is to check if the date today is less than 5 or not. If it's 1, user can input any date, if it's 0, only on the current month and later.

CASE WHEN DATEPART(day, GetUTCDate()) <5 OR (DATEPART(day, GetUTCDate()) >= 5 AND DATEPART(month,GetUTCDate()) <= DATEPART(month, [@field:Date]))

THEN 1

ELSE 0

END

Script on the footer: (change the number on cbParamVirtual1 depending in your Virtual Field)

<script>

document.addEventListener("BeforeFormSubmit", function(e){

var a= document.querySelector("input[name='cbParamVirtual1']").value;

if (a == 0){
e.preventDefault();
alert("Please input Date within or after the current month");

}

});


</script>

 

Link to post
Share on other sites

You absolutely nailed it!!!  It seems so simple now that I actually see it.  I will hang on to this code and example since I'm sure I can find other uses for it going forward.  And also adapt it to some other scenarios too.  Again, thanks so much for the fast solution.

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...
×
×
  • Create New...