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

Question

Question

Conditionally hide save as draft button

asked on November 15, 2017

I am trying to conditionally hide the save as draft button until a specific field is not blank.  I have tried plagiarizing some JavaScript and manipulating it, as I don't know JavaScript at all, but have usually been able to get it to work after some trial and error.  I can't seem to get this one to work though.  Any help is appreciated.

 

$(document).ready(function() {
  if ($('.PolyType input').val() == ""){  
	$('#IsDraft').parent().hide();}
});

 

0 0

Answer

SELECTED ANSWER
replied on November 16, 2017
$(document).ready(function() {
  $('.draft-btn').parent().hide();
  $('.polyType input').on('change', function () {
    if ($(this).val() == "") {
      $('.draft-btn').parent().hide();
    }
    else {
      $('.draft-btn').parent().show();      
    }
  })
});

Line 1: calls the function on page load (in your code, it checks your condition once on document ready and that's it)

Line 2: sets the Save as Draft button to hidden by default

Lines 5 + 8: hides or shows the button depending on whether the field is filled or not. Thing to note here is that the class you want to target is "draft-btn". You can always right click elements in your form preview page and click inspect to find the element's properties.

0 0
replied on November 20, 2017

This worked wonderfully...thank you.

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.