Tyler Posted November 20, 2020 Report Share Posted November 20, 2020 I am trying to add Javascript to validate/limit the acceptable date range for a tabular inline add. I have tried several suggestions from various forum posts, but cannot get it to work. I started with this code as a form of this does work in a different application (https://forums.caspio.com/topic/16261-validate-field-value-before-submit-in-tabular-search-report-both-table-and-details/). Please help. <script> var nameOfField = "InlineAddDate"; document.addEventListener('DOMSubtreeModified', function(){ if(document.getElementsByName(nameOfField)[0]) { document.getElementsByName(nameOfField)[0].addEventListener('change', function(){ var cash = document.getElementsByName(nameOfField)[0].value; var sDate = new Date(cash); var prevMonday = new Date(); prevMonday.setDate(prevMonday.getDate() - (prevMonday.getDay() + 6) % 7); var nextSunday = new Date(); nextSunday.setDate(nextSunday.getDate() + (0+(7-nextSunday.getDay())) % 7); if (sDate < prevMonday || sDate>nextSunday){ alert("Enter a valid date between the previous Monday and the next Sunday."); document.getElementsByName(nameOfField)[0].value=""; document.getElementsByName(nameOfField)[0].focus(); }); } }); </script> Quote Link to comment Share on other sites More sharing options...
Vitalikssssss Posted November 23, 2020 Report Share Posted November 23, 2020 Hi @Tyler, I can suggest using a different approach for this case that does not require JS snippet. You may create a lookup table that would be prefilled with date range Monday-Sunday (current week) with a help of Application Task. The Task might look like the following: You may use this lookup table as a source for a dropdown with predefined options. Hope this helps. Regards, Vitalikssssss Tyler 2 Quote Link to comment Share on other sites More sharing options...
Tyler Posted November 24, 2020 Author Report Share Posted November 24, 2020 @Vitalikssssss That is a brilliant approach. Thank you so much for the suggestion and I think it will work perfectly for my needs! I will implement and will post back If i have any difficulties. Out of curiosity though, is there a way to do this with a JS snippet? I would assume we can, but it wouldn't be as neat as what you suggested. Thanks again! Tyler 16 hours ago, Vitalikssssss said: Hi @Tyler, I can suggest using a different approach for this case that does not require JS snippet. You may create a lookup table that would be prefilled with date range Monday-Sunday (current week) with a help of Application Task. The Task might look like the following: You may use this lookup table as a source for a dropdown with predefined options. Hope this helps. Regards, Vitalikssssss 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.