You are viewing limited content. For full access, please sign in.

Question

Question

coding does not work on second form

asked on January 17, 2020

I have the following code on a submission form. It changes the text color if the number is not normal.

$(document).ready(function(){
  // detects changes in the "Scheduled Hours" table
  // filtered to only react to changes in the "hours worked" field
  // this "event bubbling" is usually the best way to deal with table rows
  $('.hoursTable table').on('change','.hoursWorked input',function(){
    // get the value of the normal hours and the field that changed
    var normal = parseInt($('.normalHours input').val());
    var actual = parseInt($(this).val());
    
    // verify that both values are numbers and check if the actual is higher
    if(!isNaN(normal) && !isNaN(actual) && actual > normal){
      // add a class to flag it for the highlighting
      $(this).addClass('abnormalHours');
    }
    // otherwise, treat it like a normal field
    else{
      $(this).removeClass('abnormalHours');
    }
  });
});

It works great on the initial form, but will not work on the subsequent form.

Is there a way I can make it work on the secondary form? Ideally, I would also like it to be read-only, but can make due.

Here is what it looks like on the initial submission. On the second form, the color does not stay.

 

When the fields are populated from the first form to the second form, there is no change, so it does not run...at least that is what I am assuming. The code I am providing is the result from another question. I am new to coding so other than basic items, I am at a loss.

 

0 0

Replies

replied on January 17, 2020

Use onlookupcomplete event if you're running Forms 10.2 or later.

This thread has a nice code example https://answers.laserfiche.com/questions/108471/Can-we-get-a-lookups-complete-custom-event-listener-please#164655

0 0
replied on January 17, 2020

You are correct, your code currently only runs on a change event. Create a copy of your code and logic out of the change event listener(before ('.hoursTable table').on('change','.hoursWorked input',function(){), directly into the document ready function so it runs on page load.

 

You can also look at creating a function so you are not duplicating your code but that is a little more advanced.

 

You are not allowed to follow up in this post.

Sign in to reply to this post.