jimarch Posted June 7, 2021 Report Share Posted June 7, 2021 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. Quote Link to comment Share on other sites More sharing options...
TellMeWhy Posted June 8, 2021 Report Share Posted June 8, 2021 On 6/7/2021 at 3:00 PM, 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> If you want this to trigger on change of the field that is being used in the Calculated Field. Change the InsertRecordFIELDNAME to your actual field's id cbParamVirtual1 to your Virtual Field's name if it's 1 2 3 or whatevers <script> document.getElementById("InsertRecordFIELDNAME").addEventListener("change", function(e){ document.querySelector("input[name='cbParamVirtual1']").addEventListener("change", function checker(){ var a= document.querySelector("input[name='cbParamVirtual1']").value; if (a == 0){ //if Calculated Value is 0 then alert alert("Please input Date within or after the current month"); //add another code } this.removeEventListener("change",checker); }); }); </script> jimarch, pmcfarlain and melsenc 3 Quote Link to comment Share on other sites More sharing options...
jimarch Posted June 8, 2021 Author Report Share Posted June 8, 2021 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. TellMeWhy 1 Quote Link to comment Share on other sites More sharing options...
pmcfarlain Posted July 22, 2021 Report Share Posted July 22, 2021 On 6/8/2021 at 12:03 PM, TellMeWhy said: 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> If you want this to trigger on change of the field that is being used in the Calculated Field. Change the InsertRecordFIELDNAME to your actual field's id cbParamVirtual1 to your Virtual Field's name if it's 1 2 3 or whatevers <script> document.getElementById("InsertRecordFIELDNAME").addEventListener("change", function(e){ document.querySelector("input[name='cbParamVirtual1']").addEventListener("change", function checker(){ var a= document.querySelector("input[name='cbParamVirtual1']").value; if (a == 0){ //if Calculated Value is 0 then alert alert("Please input Date within or after the current month"); //add another code } this.removeEventListener("change",checker); }); }); </script> Will this code work for edits made on Search/Report datapages too? I'm trying to validate that an updated/inserted date is not more than 1 week before the current date. And if so, where does the last string of code go? Quote Link to comment Share on other sites More sharing options...
TellMeWhy Posted July 22, 2021 Report Share Posted July 22, 2021 6 minutes ago, pmcfarlain said: Will this code work for edits made on Search/Report datapages too? I'm trying to validate that an updated/inserted date is not more than 1 week before the current date. And if so, where does the last string of code go? Are you using Inline Edit and Inline Insert? If so, this will not work, because Results page is an entirely different behavior Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.