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

Question

Question

clear field upon clicking submit

asked on June 28, 2017 Show version history

I have a form that goes through multiple people for authorization.  I have a radio button field that is required before the submit button appears.  Below is the button field.  The purpose is to be a reminder to check all info is complete.

When "Yes" is selected, the submit button appears.  Here is my code to make the Submit button appear...

$(document).ready(function() {
    var $submit = $('.Submit');
    $submit.hide();
    $('.verification input').on('change',function() {
      if ($(this).val() =='Yes') {
        $submit.show();
        } else {
            $submit.hide();
        }
    });
});

This is working with the first person, but it does not for the second person.  The information remains in the second submission from the first user, and the submit button does not appear for the second person.  Ideally, I would like the information to clear either upon submission of the first form, or be triggered to clear by a user change.

I tried coding the form to clear the field by adding this code...

$(document).ready(function(){

setTimeout(function(){

  $(".verification input").prop('checked', false);
  $('.verification input').val('');

}, 4000);

});

It works to clear the field information, but it no longer triggers the submit button to appear when the second user enters "Yes".

Does anyone have any solutions/ideas?  

1 0

Answer

SELECTED ANSWER
replied on June 29, 2017

1. Since the field is required, if you choose to clear it on clicking submit, the form won't pass backend validation;

2. In the script you used for clearing field value, $('.verification input').val('') will not uncheck, but rather change the value of the input element to empty. The empty value won't meet your condition $(this).val() =='Yes'. Remove this line should make the script work.

1 0

Replies

replied on June 28, 2017

Mary,

Since you're already using JavaScript to show/hide the Submit button, you could just replace the button with one in a Custom HTML element; those won't carry values over from one form to the next, which is the problem you are currently facing.

However, as far as "best practice" goes, you should really be using a checkbox and not a radio. Radio buttons are intended for multiple choice, are not meant to be "cleared," and events don't trigger the same as they do for other html elements.

If you add code to clear/uncheck it and trigger the change event on document ready, it will uncheck the box and therefore hide the submit button every time the form loads regardless of the previous user's actions.

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

Sign in to reply to this post.