Jump to content

Data Validation for Tabular Report Inline Edit - If Number Field is Greater Than Calc Field


Recommended Posts

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.

previnline.thumb.PNG.73c8d7e1a55cd86e67443d6f452cbd1b.PNG

 

Any help or ideas would be appreciated!

 

 

previnline.PNG

Link to comment
Share on other sites

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();
                }
            });
        }
});

 

Link to comment
Share on other sites

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>

 

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