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

Question

Question

Hiding the Submit button

asked on April 26, 2019

Hello!

I have a couple forms that are solely used for custom tabs in the web client.  In the Form URL, I am pulling metadata values from the document.  My goal is that when a certain document is selected and the contract type is populated in the form field 138, the submit button will show and conversely be hidden when another contract type is selected.  The code below works, but only when the drop down value is manually changed.  The contract type field is hidden so the end user doesn't know it exists.  As it stands now, for all values the Submit button is hidden when the page loads.  If I unhide the contract type field and manually select a contract type, the Submit field is hidden or shown based on the value.

 

Any help would be appreciated!

 

Thanks.

 

 

$(document).ready(function() {

  //cache the elements we will use
  var $submit = $('.Submit');
  var $Field138 = $('#Field138');

  //hide the submit button
  $submit.hide();

  //bind event handler to the dropdown field
  $Field138.change(function() {

    //if the user selects what we want, show the submit button
    if ($Field138.find(':selected').val() === "Master Services Agreement"){
      
      $submit.show();
    }
    
    else if ($Field138.find(':selected').val() === "Contracts (Other than MSA)"){
      
      $submit.show();
    }
    //if not, hide it
    else {
      
      $submit.hide();
    }
  });
});

 

0 0

Answer

SELECTED ANSWER
replied on April 28, 2019

It sounds like the issue you're having is that values provided via URL do not trigger a change event, at least not before hide the submit button and assign your event handler.

You could put your code into a named function, set that to be called on the change event, and call it directly some time in the the document ready event.

That way when the form first loads it will always execute at least once. (On a side note, you can use .val() directly on the field, the find.(':selected') is not necessary.

 

That being said, I would go a different direction.

  1. Hide the built-in Submit button with CSS so it is never visible
  2. Create a Custom HTML element with the following HTML
    • <button type="Submit">Submit</button>
    • This behaves the same as the built-in submit button (form validation and such).
  3. Set a Field Rule to show/hide your custom button with the values you listed above

This approach requires no custom JavaScript at all, and should work when you load the form with URL parameters.

 

0 0
replied on April 29, 2019

Hey Jason,

Thanks for the response.  I found another post of yours from last month regarding the same topic.  Worked perfectly!

I also pulled the CSS attributes from the native submit button and applied it to the Custom HTML.

 

Thanks!

Tom

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.