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

Question

Question

javascript help

asked on November 25, 2019

Hi All,

I'm stuck! I am trying to hide the submit button unless the folder ID number (input in #q17) is 1652011 (automatically imported from the repository with a custom button).  I'd like that field to be hidden always, but when it's hidden, it doesn't seem to work.  When I show it, the submit button will appear with the right value when I click out of the text box on my form.  What's wrong?

 

    $(document).ready(function() {
      $('.Submit').hide();
      $('#q17 input').on('blur', function() {
        if ($('#q17 input').val() == "1652011" ) {
          $('.Submit').show();
        } else {
          $('.Submit').hide();
        }
      });
    });

 

 

0 0

Answer

SELECTED ANSWER
replied on November 27, 2019

I figured it out! Thanks for putting me on the right track.  The problem is that I could not find the right event to describe the when the folder ID is imported into my form.  "Change" didn't trigger, neither did "input."  Things like "blur" and "click" worked when users interacted with the field, but I didn't want them to interact with it, in fact I preferred to keep it hidden.

Solution: I changed the event trigger to be when a user clicks a DIFFERENT (and required) field in the form! That also allows me to hide the field.  

Thanks to you both for getting me to where I needed to go, I really appreciate it!

 

0 0

Replies

replied on November 25, 2019

How are you filling q17 input when it is hidden? Are you triggering a blur event after updating the q17 input?

0 0
replied on November 26, 2019

Try this

$(document).ready(function() {
     
  $('.Submit').hide();
  
  $('#q17').change(function(){
  
    if ($('#q17 input').val() === "1652011" ) {
    
      $('.Submit').show();
      
    } else {
    
      $('.Submit').hide();
      
    }
    
  });
  
});

 

replied on November 26, 2019 Show version history

Blur only occurs when a field loses focus. So, if it's hidden, then there's no way for the field to lose focus and trigger the event that shows or hides the submit button.

Are you filling q17 with a lookup? In that case something like this might work.

$(document).ready(function() {
    $(document).on("lookupcomplete", function (event) // this even fires when _any_ lookup on the page completes. It's possible to restrict this to specific lookups if needed
    {
        if ($('#q17 input').val() == "1652011" ) { // now the show/hide logic should fire without needing user intervention
          $('.Submit').show();
        } else {
          $('.Submit').hide();
        }
    });
});

 

0 0
replied on November 26, 2019

Thanks Devin and Michael!

That makes sense.  q17 is getting its input from a command associated with a custom button in the repository.  When the user clicks that button in the repository, it opens my form in a browser and puts the folder ID from the entry into the Folder ID field using a token in the command.  What function do I use in that case?

 

Thanks! 

0 0
replied on November 26, 2019 Show version history

You can trigger a blur event ($('#q7 input').trigger('blur');), but normally I would use change ($('#q7 input').trigger('change');) as that is more descriptive of what occurs. You need to trigger the change for changes that code makes. If you are using the URL parameters to fill it in, you could possibly use the $(document).ready function instead.

2 0
replied on November 26, 2019

Thanks Michael! Would that go in your code or mine? I'm brand new and so far am just learning by copying.  If you'd be willing to put it all together for me, I'd really appreciate it.  Thanks!

0 0
SELECTED ANSWER
replied on November 27, 2019

I figured it out! Thanks for putting me on the right track.  The problem is that I could not find the right event to describe the when the folder ID is imported into my form.  "Change" didn't trigger, neither did "input."  Things like "blur" and "click" worked when users interacted with the field, but I didn't want them to interact with it, in fact I preferred to keep it hidden.

Solution: I changed the event trigger to be when a user clicks a DIFFERENT (and required) field in the form! That also allows me to hide the field.  

Thanks to you both for getting me to where I needed to go, I really appreciate it!

 

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

Sign in to reply to this post.