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

Question

Question

Need to trigger lookup when hidden field with a default becomes visible

asked on January 19, 2021 Show version history

I need to trigger an SQL lookup when a hidden field with a default becomes visible on the form.  The hidden field, once no longer hidden, shows a default name for the lookup to check against in order to pull in the format needed for Forms to assign the next task to.  The lookup is not triggering.

The hidden field shows up when a radio button choice of "ASB Member" is chosen.

Researching others' posts on this topic, I have found a few pieces to use, but I can't seem to find the right JavaScript combination to get it working.  Can someone help me with the exact JavaScript?

  • This piece tells it which field needs to behave as if it was just filled in order to trigger the lookup:  ... $("#Field61").trigger('change');   I'm assuming to be placed right after: $(document).on('ready', function() { but I believe it's not working because the field is hidden when the form first loads.
  • This piece I found along with comments that indicated to me that lookups will not work on hidden fields unless this piece is used? ...  function requiredfilled() ... { ...  return _.every($('li:has(.cf-required):visible input,li:has(.cf-required):visible textarea'), function(elm) {return $(elm).val() != '';}); ... }
0 0

Answer

SELECTED ANSWER
replied on January 21, 2021 Show version history

Hello Connie,

 

If I understood your question correctly, basically you need to trigger the lookup once the radio button choice "ASB Member" is chosen and use the hidden field default value as an input for the lookup.

 

I did not find any trouble doing it without jQuery in the initiation form (field rule to hide and show the field, default value on the field, lookup rule)

So I assume you are facing this issue on another step (other than the initiation form).

In all cases, the below script will trigger the change of the hidden field to have the default value, once the radio button value has changed to "ASB Member".

 

$(document).ready(function(){
  
  $('.radioBtnClass input').change(function(){
    
    //if needed without user input on radio button just use the below lines.
if($('.radioBtnClass input').val()=='ASB Member'){
    $('.hiddenFieldClass input').val($('.hiddenFieldClass input').attr('default-val'));
    $('.hiddenFieldClass input').trigger('change');
     }
  }); 
  
});

Hope it helps.

 

Maher.

 

 

0 0
replied on January 21, 2021

Thanks, Maher!  I must be missing something.  I've tried numerous versions of your code, but it's not working and I know it is probably because I didn't change the number of brackets at the bottom when I tried removing some of the lines.  I wish I had time to take a full course on JavaScript.

To answer your questions first:

  • It is the initial form submission where this needs to activate so I can get the approval assigned to a specific person in our Org.  I could hard code the guys name in that spot easily, but I'm working on eliminating all places where I would have to change hard coded names when staff quit and new people are hired.
  • Yes, I need the default value of the newly unhidden field to set off a lookup, which will fill another hidden field with the value needed for assigning the next task.  I would prefer to keep both fields hidden, but if the lookup needs it to be unhidden, then it can be.
  • Initially, I had the trigger to unhide the field (with the default info) when the ASB Member name field is not empty.  After seeing your code, I changed it to unhide the field when the radio button choice of ASB Member was picked.

 

What I've tried:

  • I tried your code as is (no changes) with the radioBtnClass in the Advanced tab of the radio button field and the hiddenFieldClass in the Advanced tab of the field with the default value
  • Then I reread your code where it says "if needed without user input on radio button just use the below lines" so decided to try it without the $('.radioBtnClass input').change(function(){ line.
  • Then I tried it without the $(document).ready(function(){ line since I realized I really don't need this to happen upon the form loading if I'm attempting code to trigger when a radio button is the trigger.

 

0 0
replied on January 21, 2021

I tried this as well (a combination of yours and a line from something on another form)

$(document).ready(function() {
$('.checkbox').click(function () {
if($('input[value="ASB Member"]').is(':checked')){
    $('.hiddenFieldClass input').val($('.hiddenFieldClass input').attr('default-val'));
    $('.hiddenFieldClass input').trigger('change');
     }
  }); 
  
});

replied on January 21, 2021

I tried this, as well (a combination of your code and a line given to me on another form).

$(document).ready(function() {
$('.radioBtnClass').click(function () {
if($('input[value="ASB Member"]').is(':checked')){
    $('.hiddenFieldClass input').val($('.hiddenFieldClass input').attr('default-val'));
    $('.hiddenFieldClass input').trigger('change');
     }
  }); 
  
});

0 0
replied on January 21, 2021 Show version history

OH!  I GOT IT!  My look up rule was wrong!  It was saying, if this default value is (this name) then fill the other hidden field with (this).  What it needed to say was, if this default value is (this JOB DESCRIPTION) then fill the other hidden field with this.  As soon as I made that change, it worked!  Thanks!

This is now working even with both fields remaining hidden the whole time!

I now realize it was the lookup rule that was the problem the whole time and now it is working even without the JavaScript!  *feeling sheepish*

1 0
replied on January 22, 2021

It happens laugh

Glad you worked it out!!

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.