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

Question

Question

How to Only Show Field if Field 2 Does Not Have Data After Something Entered In Field 1?

asked on July 10, 2015

We have a form that does multiple database lookups at different times when data is entered into the form. When the form is first loaded, it does a database lookup to find the supervisor information of the person filling out the form.

There are 2 fields, first name and last name, that the person filling out the form fills in. The name they enter is who the form is actually form (usually for another employee). The 2 fields are filled by a database lookup so users typing in can choose from a drop-down list of names. Once the name is entered another database lookup is performed to grab the supervisor information of the name that was entered.

Here's the fun part. Some employee's have more than 1 supervisor, so sometimes the supervisor info fields are not populated because there was more than one record returned. In that case, we have another field called Supervisor Name that gets populated with the results of the multiple supervisors and allows a user to select one of the names. When the name is selected a lookup is performed again to populate the supervisor information.

The Issue
I have a Field Rule that states to only show the Supervisor Name field if one of the supervisor information fields named Employee Supervisors Email is blank. It's all fine and dandy, except that will be always be blank when the form initially loads until someone tries to enter an employee name. I would like to be able to hide the Supervisor Name field until the lookup is performed after the submitter fills in the First Name field. Then at that point, if the Employee Supervisors Email is still blank, to show the Supervisor Name field.

Is this at all possible?

0 0

Answer

APPROVED ANSWER
replied on July 10, 2015

This is possible with JavaScript. In the document ready function, have the "Supervisor Name" field hidden. Then have code that checks if the Autofill button has been clicked yet. It can be something trivial like if the button is clicked, fill a separate hidden field with some value. Lastly, for the "Employee Supervisors Email" field, you can use an "on change lookup" where if that field itself is empty and if the hidden "Autofill click check" field has the value, then show the "Supervisor Name" field, else hide the "Supervisor Name" field.

Below is my Javascript:

$(document).ready(function () {
  
  $('.supname').hide(); //Supervisor Name field
  $('.autofillcheck').hide(); //Other field to track Autofill click
  
  $('.autofill').click(function() {
    $('.autofillcheck input').val("y"); //Set AutofillCheck field to y
  });
  
  $('.empsupemail input').on('change lookup', function() {
    if ((!$('.empsupemail input').val()) & ($('.autofillcheck input').val()=="y")) {
      $('.supname').show();
    } else {
      $('.supname').hide();
    }
  });
  
});

 

0 0

Replies

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

Sign in to reply to this post.