abitaquest Posted August 16, 2018 Report Share Posted August 16, 2018 Years ago I added some JavaScript to my forms to prevent clients from selecting a "due date" that isn't at least two weeks in the future. Recently that code has stopped working, and all submissions are allowed through, regardless of the date selected. I think this may be tied to the recent Caspio updates. At least, that's all that I can see; the forms themselves haven't changed. Below I'm pasting my JS, which resides in the footer area of my forms. Any ideas would be greatly appreciated. Thanks! (BTW, I know two weeks is 14 days, not 13. But my users don't seem to recognize that, so I made this small allowance.) <SCRIPT LANGUAGE="JavaScript"> function check_date() { var entered_value = document.getElementById("InsertRecorddateNeeded").value; var entered_date = new Date(entered_value); var two_week_date = new Date(); two_week_date.setDate(two_week_date.getDate() + 13); if(entered_date < two_week_date) { alert("Must be at least 2 weeks in future"); return false; } } document.getElementById("caspioform").onsubmit=check_date; </SCRIPT> Quote Link to comment Share on other sites More sharing options...
IMDora Posted August 24, 2018 Report Share Posted August 24, 2018 @abitaquest, There's a possibility that the reason it's not working now is because of the recent Caspio update. Event like onsubmit will no longer be supported and you need to use Caspio's built-in event handlers. Kindly please check the link below for more information: https://howto.caspio.com/release-notes/caspio-bridge-13-0/13-0-impacted-areas/ https://howto.caspio.com/datapages/ajax-loading/ I hope this helps. abitaquest and LunaLovegood 1 1 Quote Link to comment Share on other sites More sharing options...
abitaquest Posted August 24, 2018 Author Report Share Posted August 24, 2018 You're right, IMDora! I had allowed AJAX to run on that form after the most recent release. Disabling AJAX put it back the way it belonged. Everything works again! I can't believe I didn't think of that myself. Much appreciated! Quote Link to comment Share on other sites More sharing options...
edujobs2k18 Posted September 3, 2018 Report Share Posted September 3, 2018 Hi Guys, How to block user to choose past date from calendar in a form? User should not allow to choose a past date from calendar in "Date0" field. I am unable to do so. Quote Link to comment Share on other sites More sharing options...
abitaquest Posted September 4, 2018 Author Report Share Posted September 4, 2018 Hi, edujobs2k10 — This is untested, but it should work. I only changed the variable name and set "permitted_date" to be today's date plus 0 days, then changed the text of the error message. The user should now only be allowed to select today or a day in the future, nothing in the past. First, be sure that AJAX isn't allowed to run on your form. Then, paste the following into your form's footer: <SCRIPT LANGUAGE="JavaScript"> function check_date() { var entered_value = document.getElementById("InsertRecorddateNeeded").value; var entered_date = new Date(entered_value); var permitted_date = new Date(); permitted_date.setDate(permitted_date.getDate() + 0); if(entered_date < permitted_date) { alert("Cannot be a date in the past"); return false; } } document.getElementById("caspioform").onsubmit=check_date; </SCRIPT> Quote Link to comment Share on other sites More sharing options...
Vitalikssssss Posted September 6, 2018 Report Share Posted September 6, 2018 On 9/3/2018 at 9:47 AM, edujobs2k18 said: Hi Guys, How to block user to choose past date from calendar in a form? User should not allow to choose a past date from calendar in "Date0" field. I am unable to do so. Hi @edujobs2k18, You may try to use the following Javascript solution: <script type="text/javascript"> document.addEventListener('BeforeFormSubmit', function(event) { var entered_value = document.getElementById("InsertRecordDate0").value; var entered_date = new Date(entered_value); var permitted_date = new Date(); permitted_date.setDate(permitted_date.getDate()); if(entered_date < permitted_date) { alert("Cannot be a date in the past"); return false; } }); </script> This solution is designed for Submission form with AJAX enabled. Also, field name "Date0" used from your post. Hope this helps. Regards, vitalikssssss abitaquest 1 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.