Jump to content

Validate field value before submit in Tabular Search Report (both table and details)


Recommended Posts

I am trying to run the following JS to make sure the value in one field has been entered in decimal form, but I can't get it to work. I have tried multiple iterations/adaptions of suggestions I have found on the forums. Any help would be appreciated. Thank you!

<script type="text/javascript">
document.addEventListener('BeforeFormSubmit', function () {

event.preventDefault();

var a = document.getElementsByName("InsertRecordSplit_To_Agent");

if (a[0].value <=0 || a[0].value >1) {
alert('Split to Agent value is not in the correct range. Please enter split percentage in decimal form.');
}

else {
document.forms["caspioform"].submit();
}

});
</script>

 

Forum posts/pages I have tried to use for adaptions/reference

https://howto.caspio.com/datapages/ajax-loading/

 

Link to post
Share on other sites

Hello @Tyler

In the title you mentioned that you need to validate the  value on the Report DataPage.

It is possible on the Details screen with the slight changes to the code you were trying  to use. 

Please change the name of the element from "InsertRecordSplit_To_Agent" to "EditRecordSplit_To_Agent".

<script type="text/javascript">
document.addEventListener('BeforeFormSubmit', function () {

event.preventDefault();

var a = document.getElementsByName("EditRecordSplit_To_Agent");

if (a[0].value <=0 || a[0].value >1) {
alert('Split to Agent value is not in the correct range. Please enter split percentage in decimal form.');
}

else {
document.forms["caspioform"].submit();
}

});
</script>

If you need to validate the value on the Result screen, it is quite challenging. Do you use Inline Insert option (Add Records)?

Feel free to update this thread if you have further questions. 

Link to post
Share on other sites
  • 4 weeks later...

Leaving this here for future members.

 

I was able to get the Inline Insert (Add Records) to validate by using the following code.

 

<script>
var nameOfField = "InlineAddSplit_Percentage_To_Agent";

document.addEventListener('DOMSubtreeModified', function(){
  
        if(document.getElementsByName(nameOfField)[0])
    {
          document.getElementsByName(nameOfField)[0].addEventListener('change', function(){

                var cash= document.getElementsByName(nameOfField)[0].value;

                    if(isNaN(cash))
                {
                    alert("You have entered an invalid value in the Split to Agent field. Value must be numeric. Do not include letters or symbols.");
                    document.getElementsByName(nameOfField)[0].value="";
                    document.getElementsByName(nameOfField)[0].focus();
                }
                    else if((cash) < 0)
                {
                    alert("You have entered an invalid value in the Split to Agent field. Value cannot be a negative or zero amount.");
                    document.getElementsByName(nameOfField)[0].value="";
                    document.getElementsByName(nameOfField)[0].focus();
                }
                    else if((cash) > 1)
                {
                    alert("You have entered an invalid value in the Split to Agent field. Percentage value must be entered in decimal form.");
                    document.getElementsByName(nameOfField)[0].value="";
                    document.getElementsByName(nameOfField)[0].focus();
                }
            });
        }
});
          
</script>

 

Link to post
Share on other sites

@CoopperBackpack

 

I do use the inline Add extensively in my App due to easy of workflow needs and visibility of data during entry.  As I posted above, I was able to find a solution to the problem (forgot to post about that solution until now :( ), but now I have a different (but similar) problem that I need to find a solution for.

 

I made a new post here about it and would appreciate any insight you may have into this.

https://forums.caspio.com/topic/17111-date-entry-validationlimitation-in-tabular-report-inlineadd/

 

Thank you for your response earlier. Also thank you @Nuke354 for that helpful link as well.

 

Tyler

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