Tyler Posted October 20, 2020 Report Share Posted October 20, 2020 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/ Quote Link to comment Share on other sites More sharing options...
CoopperBackpack Posted October 23, 2020 Report Share Posted October 23, 2020 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. Quote Link to comment Share on other sites More sharing options...
Nuke354 Posted October 23, 2020 Report Share Posted October 23, 2020 @Tyler In addition, you may refer to our JS Form Elements Guide: Quote Link to comment Share on other sites More sharing options...
Tyler Posted November 20, 2020 Author Report Share Posted November 20, 2020 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> Amyas 1 Quote Link to comment Share on other sites More sharing options...
Tyler Posted November 20, 2020 Author Report Share Posted November 20, 2020 @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 Quote Link to comment Share on other sites More sharing options...
futurist Posted November 20, 2023 Report Share Posted November 20, 2023 You may refer to this Forum post to validate data entry to make sure that they follow this format: www.websitenamehere.com 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.