Jump to content

Date Entry validation/limitation in Tabular Report "InlineAdd"


Recommended Posts

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>

 

Link to comment
Share on other sites

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: 

a6f7305064be.png

You may use this lookup table as a source for a dropdown with predefined options.

Hope this helps.

Regards,

Vitalikssssss

Link to comment
Share on other sites

@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: 

a6f7305064be.png

You may use this lookup table as a source for a dropdown with predefined options.

Hope this helps.

Regards,

Vitalikssssss

 

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