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

Question

Question

Bypassing Required Fields on Form Reject

asked on February 15, 2017

I have a form that is loaded from a User Task.  It has buttons to Approve, Submit, or Reject, with custom naming of those buttons.

In the case of the Reject Button, it routes the form to another employee to request assistance with the form.

I want the form to only require completion of fields when approved or submitted, but allow incomplete fields on reject (since I'm routing to that other employee to help complete that form.

This is the code I'm using:

$(".action-btn.Reject").on('click', function() {    
    $('*[required]').each(function() { 
      $(this).removeClass('required')
      $(this).removeAttr('required');
    }); 
});

When I tested this with the Submit button in the form preview, it worked, so I changed it to the Reject button and then went to test it in the live processing of the form.

Initially the form appears to accept the "reject" button click, but then comes back with an error.

So it appears that there are two layers of required field validation, and I've managed to remove the required field flags that are used in the first validation (while the form is still displayed) but I'm still catching the secondary validation (after the form has been removed from display).

I'm on version 10.2

Anyone have any suggestions?

1 0

Answer

SELECTED ANSWER
replied on February 15, 2017

Yes, Forms 10.2 added a new backend validation option that is (I believe) turned on by default on new processes. You should be able to turn it off from Form Settings (gear icon), at the bottom.

1 1
replied on August 8, 2019

This does not seem to work for 10.4.0

2 0

Replies

replied on April 1, 2021

Works great! Thanks so much!

1 0
replied on February 15, 2017

That was it, thank you so much @████████!

0 0
replied on August 2, 2018

Hi @Matthew Tingey, 

I found your post and am trying to do a very similar thing: I have a form for managers to Approve/Reject (with custom naming of those buttons), and I'd like to bypass the required fields if they click on the Reject button. 

I've got the Backend Validation set to No Validation (I'm on 10.2, as well). 

I've copied your code to my CSS/Javascript page, but it doesn't appear to be working. Was there another element (such as Class) that you set up that I'm overlooking? 

My apologies as I'm not overly educated in Javascript.  (just enough to be dangerous, know what I mean smiley) And I sincerely appreciate any direction you may have. Thank you! 

Sarah

0 0
replied on August 6, 2018

Hey @████████ - I'd be happy to take a look at what you've got.  Do you have additional Javascript (in which case, would you mind sharing?) or are you using just what was posted here?

 

0 0
replied on August 7, 2018

Thanks Matthew! I have other Javascript that controls other fields, like appending our domain name to the user ID for routing, and filling a hidden field when a certain radio button is selected; but as far as controlling required fields when the Reject button is selected, I just took what was in this post and pasted it to the end. 

$(".action-btn.Reject").on('click', function() {    
    $("*[required]").each(function() { 
      $(this).removeClass('required')
      $(this).removeAttr('required');
    }); 
});

Would it help to see everything?

Is the "*[required]" used to tag all required fields?  Or is there something else I need to set up to do that? 

Again, thank you so much for your help.  :]

0 0
replied on August 7, 2018

Yes - it should be cycling through every required field and removing the required status prior to the processing of the rejection.

If you wouldn't mind sharing your full Javascript - that would be helpful.  Unless it is hundreds of lines long that is wink

0 0
replied on August 7, 2018

Well...it's not hundreds... :) 

$(document).ready(function () {
     $('.mgrid input.singleline').change(function () {
       $(this).val('domain\\' + this.value);
    });
});
$(document).ready(function() {
  	 $('.userID1 input.singleline').trigger('change', function() {
       $(this).val('domain\\' + this.value);
     });
});
$(document).ready(function () {
  $('.radio input').change(function () {
       $(".radio input:checked").each(function(){
    if ($(this).val() == "Yes")
    {
    $('.autofill input').val('Compliance Alert!');
  }
    })     
  })
})
$(document).ready(function () {
  $('#q62 input').change(function () {
       $("#q62 input").each(function(){
    if ($(this).val() == "")
    {
    $('.autofill input').val('');
  }
    })     
  })
});
$(".action-btn.Reject").on('click', function() {    
    $("*[required]").each(function() { 
      $(this).removeClass('required')
      $(this).removeAttr('required');
    }); 
});

 

Thanks for taking a look!

0 0
replied on August 12, 2018 Show version history

Okay @████████ - here's some updated code for you.

Please note that I have NOT tested this code, I have only edited your code to resolve some immediate syntax errors that I could see.

1. All of the functions and events you have listed needed to be wrapped inside of the     $(document).ready(function () {     function - whereas you were listing a couple versions of that event function, and your reject button function wasn't in it at all.  It might or might not work to have the multiples, but this is cleaner and more reliable.

2. You were missing several semicolons.  Javascript is not very forgiving when those go missing.  The Laserfiche Forms editor doesn't have any functionality to report syntax errors to you, so you just find that your code won't function, particularly everything following that missing semi colon.

3. I added commenting for you.  This is not a requirement, but it is a best practice that I highly recommend.  When you (or another individual) has to come back to edit your code months or years later, it helps to have those comments to explain what everything does.  The comments at the end of functions are not something that most coders do, but I find it very helpful in Laserfiche Forms where the editor has less bells and whistles.  

$(document).ready(function () {
  
  //Notes to explain purpose of this function
  $('.mgrid input.singleline').change(function () {
    $(this).val('domain\\' + this.value);
  }); //end of $('.mgrid input.singleline').change(function () {
  
  //Notes to explain purpose of this function
  $('.userID1 input.singleline').trigger('change', function() {
    $(this).val('domain\\' + this.value);
  }); //end of $('.userID1 input.singleline').trigger('change', function() {
  
  //Notes to explain purpose of this function
  $('.radio input').change(function () {
    $(".radio input:checked").each(function(){
      if ($(this).val() == "Yes")
      {
        $('.autofill input').val('Compliance Alert!');
      }
    }); //end of $('.radio input').change(function () {
  }); //end of $('.radio input').change(function () {
  
  //Notes to explain purpose of this function
  $('#q62 input').change(function () {
    $("#q62 input").each(function(){
      if ($(this).val() == "")
      {
        $('.autofill input').val('');
      }
    }); //end of $("#q62 input").each(function(){     
  }); //end of $('#q62 input').change(function () {
  
  //When the user clicks the reject button, required fields are ignored.
  $(".action-btn.Reject").on('click', function() {    
    $("*[required]").each(function() { 
      $(this).removeClass('required');
      $(this).removeAttr('required');
    }); //end of $("*[required]").each(function() {  
  }); //end of $(".action-btn.Reject").on('click', function() {  
  
}); //end of $(document).ready(function () {

I hope this helps!

Oh, and if you don't know - at the top-right of that little code display, there should be a button to "view source" which will give you an easier view to copy from.  Helpful tip if you don't already know that one. wink

0 0
replied on August 13, 2018

Thank you @████████ - this is incredibly helpful. I should've guessed from past experience - those semicolons get me every time!

Obviously, you can tell the little I know was learned via trial by fire.  I can most certainly adopt your helpful tips for my own future sanity. ;) 

I'll give these updates a try and see how it goes. Thanks again for your help; this is really great! 

1 0
replied on August 21, 2018

@████████ - just curious how that worked out for you.

0 0
replied on August 27, 2018

Hello @████████ - I apologize for not responding quicker. I must confess I'm a little gun shy and I haven't tried it yet.  I definitely intend to! But I'm wanting to get all my ducks in a row, testers in order, and stars aligned before jumping off the cliff.

There's nothing more satisfying than having your code work for you, but it's a far cry from the frustration that comes when it doesn't and you don't know why! :] 

Thank you so much for checking in on me. I will work on it this week and let you know how it goes!

1 0
replied on August 28, 2018

Too true!  Good luck!

0 0
replied on April 1, 2021

I am a newbie. I copied your javascript (no other script). I went into settings and and set validation level to No Validation. It is still checking for required radio button. 

I have submit and reject buttons. No custom name. 

I have set a required button for me. To show I completed my step in the process. 

When rejection button is used I need it to route back to the person to complete their steps in the process before I can do mine (linear steps). 

 

When submit button is used I need to click the required button to show my step is complete and pass it on to the next person to do their step in the process. 

 

Any suggestions for me?

 

 

0 0
replied on April 1, 2021

There are several different scripts posted in this thread, and not all of them are full scripts that can be put right in to LFForms without any modification (at the very least, some of them are not inside a document ready function).

Can you share which code in particular you are using?

0 0
replied on April 1, 2021

Thanks for your quick response.

 

I copied the one that has comments. I took a guess. It had the if the reject button is clicked then remove class and attribute required. 

 //When the user clicks the reject button, required fields are ignored.

  $(".action-btn.Reject").on('click', function() {    

    $("*[required]").each(function() { 

      $(this).removeClass('required');

      $(this).removeAttr('required');

    }); //end of $("*[required]").each(function() {  

  }); //end of $(".action-btn.Reject").on('click', function() {  

0 0
replied on April 1, 2021

Try wrapping it in a document ready function. 

$(document).ready(function() {
  //When the user clicks the reject button, required fields are ignored.
  $(".action-btn.Reject").on('click', function() {    
    $("*[required]").each(function() { 
      $(this).removeClass('required');
      $(this).removeAttr('required');
    }); //end of $("*[required]").each(function() {  
  }); //end of $(".action-btn.Reject").on('click', function() { 
});  //end of $(document).ready(function() {

 

2 0
replied on October 5, 2022 Show version history

I just want to add that I just successfully tested a way to do this even on Cloud which does not have an option for disabling backend validation. Feel free to let me know if there is a flaw in this approach, but the basis is this:

Field1 is a required field.

Field2 is a checkbox with one choice, "Check if rejecting". It is hidden with a Field Rule.

There is another Field Rule that hides Field1 if Field2 has "Check if rejecting" checked.

With this code, we check the box. Then we call "change()" on the checkbox. Since it is the first (and only) checkbox on Field2, that would be Field2-0. This change() activates the Field Rule, and the required field gets hidden, which allows the rejection to go through.

$(document).ready(function() {
  $(".Reject").on('click', function() {    
  $('#q2 input[value=\"Check_if_rejecting"]').prop('checked',true);
  $("#Field2-0").change();
  });
});

One benefit to this rather than just removing the "requiredness" from the field(s) upon clicking Reject is that you avoid this scenario:

1) Field has constraint on it (let's say it is a Zip Code field that requires 5 digits)

2) User inputs something that violates the constraint (1234)

3) User clicks Reject

4) jQuery code removes "requiredness" from field

5) Rejection does not go through because the invalid value in the field prevents it

6) User clears out the value

7) Now they can click ANY action button and the form will go through, because they were already marked not required

Just one thing I discovered during my testing of that approach on-prem.

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

Sign in to reply to this post.