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

Question

Question

field rules after javascript

asked on October 17, 2014

How can I get field rules to re-evaluate after a checkbox is cleared with javascript?

I have a form that normally gets submitted by an employee, but sometimes AP has to request that an employee fill it out. So, I have a checkbox at the top of the form that is displayed and AP checks it if it needs to be routed to the employee. When the checkbox is checked, certain sections with required fields are hidden. The form is then routed to the employee. The problem is when the employee gets the form, the hidden sections are still hidden because the checkbox is still checked.

I added a line in the javascript section that unchecks the field. I tried the "on load" method. Neither seem to work. The hidden sections continue to stay hidden, even though the checkbox is no longer checked.

Thanks for any help you may be able to provide.

 

Here's a sample of what I've tried:

 //$('input[name=Field130]').prop("checked",false);

And:
    $('input[name=Field130]').on('load', clearSendToEmployee);
 
    function clearSendToEmployee () {
         $('input[name=Field130]').prop("checked",false);
      }
 

0 0

Answer

APPROVED ANSWER
replied on October 19, 2014 Show version history

If you've managed to find some code that works to clear the checkbox, then I think all you're missing is firing off a "change" event for it. Try adding this to your function:

function clearSendToEmployee () {
   $('input[name=Field130]').prop("checked", false);
   $('input[name=Field130]').trigger("change"); // <--- add this
}

This event is normally generated automatically when the user interacts with the form, but I don't think it happens when you change elements or properties programmatically unless you explicitly force it.

3 0

Replies

replied on October 19, 2014

Thanks, Scott! That worked. I was just missing the "change".

0 0
replied on December 18, 2014

I am attempting to hide a field based on a javascript calculation. Basically what i am trying to do is hide the "Verify Reading" field if the "variance" field is = 0.  This is a calculated field that is the difference between the user inputted "Reading" field and the look up value being populated in the currently hidden "CalcInput" field.  After reading Scott's post, I am trying the code below without any luck.  My calculation from lines 1-4 work fine but I am not familiar enough with javascript at this point to troubleshoot what changes need to be made.  Any help would be greatly appreciated.

$(document).ready(function () { 
  $('#q2 input, #q5 input').blur(function () {
    $('#q7 input').val($('#q2 input').val() - $('#q5 input').val());
  });
  
function hidevariance () {
   $('input[name=q7]').prop("0", false);
   $('input[name=q9]').trigger("hide"); 
}  
});

0 0
replied on December 18, 2014

Configure your field rule to hide the "Verify Reading" field when "Variance" is equal to 0. Then in the JavaScript section, use the following:

$(document).ready(function () {
  $('#q2 input, #q5 input').blur(function () {
    $('#q7 input').val($('#q2 input').val() - $('#q5 input').val());
    $('#q7 input').trigger("change");
  });
});

 

0 0
replied on December 18, 2014

Thank you Alexander, worked perfectly!

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.