kpcollier Posted April 24, 2023 Report Share Posted April 24, 2023 I've got a workflow similar to the one below, but I'm trying to get it to work with a calculated value in the condition. However, I think what I need is a little different. I need to be able to make sure that the Quantity input field is less than the On Hand calculated value. If not, prevent the edit. Here is what I've tried, however I am not the best at jQuery. I've also tried adding a keyup event listener on the Quantity field, to no affect. $("#cbform-improvement #Mod0InlineEdit").click(function(e){ window.alert("check"); if(document.getElementsByName("InlineEditStock_CartItems_Table_Quantity")[0].value <= document.querySelectorAll(".cbResultSetCalculatedField")[0].innerHTML) { window.alert("save!"); } else if (document.getElementsByName("InlineEditStock_CartItems_Table_Quantity")[0].value > document.querySelectorAll(".cbResultSetCalculatedField")[0].innerHTML) { window.alert("do not save!"); return false; } else { window.alert("do not save!"); return false; } }); I've also tried a calculated value solution, but this doesn't seem to prevent an inline edit like it does a submission form/update form. CASE WHEN [@field:Stock_CartItems_Table_Quantity] > [@calcfield:1] THEN CAST( 'a' + 1 as INT) END Finally, here is what it looks like on the tabular report page when editing. The "Quantity" field cannot be greater than the "On Hand" field. If it is, prevent the edit. Any help or ideas would be appreciated! Quote Link to comment Share on other sites More sharing options...
kpcollier Posted April 24, 2023 Author Report Share Posted April 24, 2023 This gets me pretty close. However, I've got a weird bug that is popping up the 2nd alert multiple times (like 7 times), even when that condition shouldn't be going off. If I put in a value that is greater than On Hand, which should set off the last Alert, I get the last alert and the 2nd alert a bunch of times. Almost there. var nameOfField = "InlineEditStock_CartItems_Table_Quantity"; document.addEventListener('DOMSubtreeModified', function(){ if(document.getElementsByName(nameOfField)[0]){ document.getElementsByName(nameOfField)[0].addEventListener('change', function(){ var insQty = document.getElementsByName(nameOfField)[0].value; var ohQty = document.getElementById("ohQty[@field:Stock_ShoppingCart_Table_CG_ID]").innerHTML; console.log(insQty); console.log(ohQty); if(isNaN(insQty)){ alert("You have entered an invalid value Quantity field. Do not include letters or symbols."); document.getElementsByName(nameOfField)[0].value=""; document.getElementsByName(nameOfField)[0].focus(); } if((insQty) < 1){ alert("Quantity cannot be a negative amount."); document.getElementsByName(nameOfField)[0].value=""; document.getElementsByName(nameOfField)[0].focus(); } if((insQty) > ohQty){ alert("Quantity cannot be greater than On Hand for non-stocked items."); document.getElementsByName(nameOfField)[0].value=""; document.getElementsByName(nameOfField)[0].focus(); } }); } }); Quote Link to comment Share on other sites More sharing options...
kpcollier Posted April 25, 2023 Author Report Share Posted April 25, 2023 Here is the solution: This will make sure the entered value is a Number, is not negative, and is less than the related calculated value. My last IF block has an extra condition to see if another field is Yes or No. You can delete this if not needed. <div id="ohQty[@field:Stock_CartItems_Table_CG_ID]">[@calcfield:1]</div> <div id="si[@field:Stock_CartItems_Table_CG_ID]" class="hideThis">[@field:Stock_CartItems_Table_Stock_Item^]</div> <script> var nameOfField = "InlineEditStock_CartItems_Table_Quantity"; document.addEventListener('DOMSubtreeModified', function(){ if(document.getElementsByName(nameOfField)[0]){ document.getElementsByName(nameOfField)[0].addEventListener('change', function(){ var insQty = document.getElementsByName(nameOfField)[0].value; var ohQty = document.getElementById("ohQty[@field:Stock_CartItems_Table_CG_ID]").innerHTML; var stockItem = document.getElementById("si[@field:Stock_CartItems_Table_CG_ID]").innerHTML; console.log(insQty); console.log(ohQty); console.log(stockItem); if(isNaN(insQty)){ alert("You have entered an invalid value for the Quantity field. Do not include letters or symbols."); document.getElementsByName(nameOfField)[0].value=""; document.getElementsByName(nameOfField)[0].focus(); } if((insQty) < 0){ alert("Quantity cannot be a negative amount."); document.getElementsByName(nameOfField)[0].value=""; document.getElementsByName(nameOfField)[0].focus(); } if((insQty) > ohQty && stockItem == "No"){ alert("Quantity cannot be greater than On Hand for non-stocked items."); document.getElementsByName(nameOfField)[0].value=""; document.getElementsByName(nameOfField)[0].focus(); } }); } }); </script> 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.