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

Question

Question

How To: Skip, Bypass, or Disable required fields validation depending on user choice

asked on October 16, 2018 Show version history

Scenario: A form has required fields. However, if the user presses a button like Reject, we don't want to require the user to fill in junk data, especially if a required field is a File Upload field. 

Goal: Skip validation if the user presses "Reject".

Steps: 

  1.  Disable backend validation on the form in question
    • On the Forms Layout tab, press the gear icon, set Backend validation to "No validation"
    • Save
  2. Add the following jquery
    $(document).ready(function (){
     
    // this binds a click action on the Reject button
      $('input.action-btn.ellipsis.Reject').on('click', function() {
    
        $('input, select').each(function() {    
    	  $(this).removeAttr('required');
        });
      }); 
    }); 
    

Result: When the users clicks the Reject form action, no validation takes place. and the Reject action path is taken in the process model. All other actions, live validation takes place and prevents the action from going through.


I've been trying to work this but didn't find an exact post. Was writing something up to save for myself and figured I'd save it here instead :) Many thanks to @Matthew Tingey for putting me down the right path based on his post https://answers.laserfiche.com/questions/141193/check-validation-before-submit#141201 . 

Forms Version 10.3.1.553

9 0

Answer

SELECTED ANSWER
replied on October 16, 2018 Show version history

Answer included in question.

6 0

Replies

replied on August 14, 2019 Show version history

Update for 10.4 - Original doesn't work for Rich Text fields, have to add "div" to the function, as follows:

// If "reject" button is clicked
    $('.Reject').click(function(){
      
      // un-require required fields for reject button
      $('input, select, div').each(function() {    
      	$(this).removeAttr('required');
      });

 

2 0
replied on October 16, 2018

Thanks Carl,

 

Exactly what I was after today!

 

Thanks again,

Ziad

0 0
replied on October 17, 2018

Glad it was useful to others!

2 0
replied on September 7, 2022

Worked like a charm!  Thanks so much for this.

0 0
replied on March 27

Hi There, 

 

This works great for classic design form. However, what would be the code for this on Laserfiche 11 on modern form designer?

I'm not much of a coder and I can't get this to work.

 

Thank you very much!​​​​​​

0 0
replied on March 27

With Forms 11 update 5 you can use field rules to accomplish this without any code.  You have an option in Field Rules to disable or validate as an optional field as the result of a condition.

1 0
replied on March 27

Thank you for your answer, but how do you bind that to Form buttons? I can see you can make the field required or optional using Validate, but when you try to set conditions, it doesn't show the form buttons. Process Step or Stage doesn't help at this time.

There are required fields on the form. But this form needs to be cancelled and we dont want users to fill out the required fields. When sser clicks on Cancel(Reject) button, the form should end it but it still asks for required fields to be filled.

0 0
replied on March 27

Not quite. In Forms 11 you are not able to make a field required or not based on the Action Button selected like what Carl mentions in the original post. You can only show or hide Action Buttons, but not take action if one is clicked.

0 0
replied on March 27

Ok, so can we use javascript to achieve this and if so, what would be the code look like?

We need those required fields in case the user submits the form. But if the form going get cancelled, the form process will end and they dont need to fill required fields just to cancel the form.

0 0
replied on March 27

Can't be done with modern Forms designer.  We still use Classic Designer for things that require Javascript field modifications, in which case you can use the code provided in the original post.

1 0
replied on March 27

I tend to use a Radio Button for approve/deny as our forms require that it is part of the saved form, so for those instances it is easier to leverage the field rules.

 

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

Sign in to reply to this post.