Tyler Posted February 8, 2021 Report Share Posted February 8, 2021 I have been pounding my head against a wall on this one. I need to do data validation for two fields in a tabular report data page in two different scenarios. I have been successfully using the following code to validate one field: <script> var nameOfField = "InlineAddWhole_Value_Perc_Split_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 number in the Split to Agent field. Value must be numeric whole value decimal. 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 number in the Split to Agent field. Value cannot be a negative amount."); document.getElementsByName(nameOfField)[0].value="0"; document.getElementsByName(nameOfField)[0].focus(); } else if((cash) > 100) { alert("You have entered an invalid number in the Split to Agent field. Percentage value must be entered as a whole value percentage. i.e. 100% = 100 and 50% = 50"); document.getElementsByName(nameOfField)[0].value="100"; document.getElementsByName(nameOfField)[0].focus(); } }); } }); </script> 1st scenario - How do I validate two different fields independently? Basically field "split to Agent" must be between 0 & 100 and field "Agent ID" must be non-zero. 2nd scenario - How do I validate two different fields dependently? IF field "split to Agent" is less than 100 THEN field "Agent ID" must be non-zero. The main issue that I am running into is that I cannot figure out how to do an event listener for more than 1 field at a time. No matter how I have tried to implement it, I can't. I would appreciate any help that I can get here. Is that possible to implement? Is there any way to implement this? Thank you in advanced! Tyler carolinuz 1 Quote Link to comment Share on other sites More sharing options...
lengleng Posted February 18, 2021 Report Share Posted February 18, 2021 I can't give you an exact code, but I can give you a suggestion, I guess? That's kind of complicated for two field validation. If you may, can you just use a Submission Form instead of Inline Insert? You can put the link on the header of your Reports DataPage and use a pop-up window. JavaScript Validation would be much easier to implement on a Submission Form, or you can even use Rules or Calculated Fields to check the field. Let's say you have Field 1 - you can then create a Virtual Field > set it to Calculated Value > check the value of Field 1 (i.e. CASE WHEN Field1 < 0 THEN "Invalid" ELSE "OK" END Then on your Field 2 - created another Virtual Field > set to Calculated Value > check the value of Field 2, you can even insert Field 1 here (i.e. CASE WHEN FIELD1 < 100 AND AGENTID = 0 THEN "INVALID" ELSE "Good" END Then on your JS code, just listen to the whole document like - document.addEventListener("change", function(e) - then, inside, if one of the calculated values is not "OK" prevent the form to submit - preventDefault(); Again, this is just a workaround I thought of, you can easily disregard if you really want to go the inline insert route 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.