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

Question

Question

forms 11 Update 3 - Scripting

asked on February 1, 2023

Hello,

One of our customer has a requirement where on "Reject"ing a Laserfiche form , comment box must be mandatory (to specify reject reason) / has to be filled.

I have been playing around with the scripting functionality in New Forms designer (11 update 3) and finding it a bit difficult to get this working. Issue is, I am unable to access the Reject button ({handlerName: "submissionHandler"});)and the comment box using the new Forms 11 designer scripting.

Has anyone come across similar requirement? 

Thanks in advance.

1 0

Replies

replied on February 2, 2023

I don't think you would be able to do this the way you have explained using the Modern designer.  Classic designer, sure, but not the Modern Designer.

It looks like the submissionHandler on the LFForm object doesn't have any way to report which button was clicked, at least not that I can find.  And you can't access the buttons directly, because the Javascript runs in a sandboxed iFrame so it's effectively running on a different webpage.

You can definitely run some code on the submissionHandler, and that triggers before it even tries to validate the other form fields.  So you could have it prompt to complete the indicated field before submission, like this: 

LFForm.onFormSubmission(function(){ 
    if (LFForm.getFieldValues({fieldId:1 }) == "") {
        return {error: "Reason for Rejection is missing.  It must be populated before submission."};
    }
}, {handlerName: "submissionHandler"});

However, that seems like an overly complicated way to require a field, you could just mark it as required.  It still is going to do it for any Submit/Approve/Reject/SaveDraft submission instead of just the Reject submission.

The Javascript functionality in the Modern Designer is so limited, that it's really hard to make it work for anything outside of the most basic functionalities - so if custom Javascript is really needed for your process, you are best still sticking to the Classic Designer.

One idea that will work with the Modern Designer is to use the field rules.  And this is really where the Modern Designer shines, because the field rule options are more powerful.  You could make it so that the Reject button isn't even shown unless your field is populated.  Unfortunately, I don't think this can be tied to the standard comment box, but could be tied to a field you add.

The field rule on the form would look something like this:

 

I also used this CSS to hide the built-in comments box, since I'm using a multi-line field for "Reason for Rejection". 

#comment-container
{
  display:none;
}

 

The form looks like this. 

When the field is not populated, the Reject button is hidden.

When the field is populated, then the Reject button is shown.

 

You could even add field rules on other fields that are normally required, but are not needed on a rejection - when the Reason for Rejection is populated.  Of course you can hide the fields.  But with the new options, you can now leave them shown but disable or change their required status.  Like this rule, that takes a field flagged as Required and disables it and switches it to optional if the rejection reason is populated. 

1 0
replied on February 2, 2023

Hi Mathew,

Thank you for the detailed explanation. I had already been down the above route but like you mentioned, referencing the comment box and identifying which submit button was something which i couldnt figure out.

Having a multi line field fails with requirement especially in case of multiple query/response loop. 

Thank you.

0 0
replied on February 2, 2023 Show version history

In that case, I think you might be stuck utilizing the Classic Designer.

The Modern Designer just doesn't provide the flexibility you need either with built-in options or with the Javascript options available.

0 0
replied on February 2, 2023

For the record, here is how I would do it on the Classic Designer: 

$(document).ready(function () {
         
  //If the Reject button is clicked, mark the comment field as required.
  $(".action-btn.Reject").on('click', function() {    
    $('#comments').addClass('required').attr('required', 'true');
  });
  
  //If the Submit, Approve, or Save buttons are clicked, mark the comment field as optional.
  $(".action-btn.Submit, .action-btn.Approve, .action-btn.Save").on('click', function() {    
    $('#comments').removeClass('required').removeAttr('required');
  });

});

 

1 0
replied on February 2, 2023

Thank you for that. Scipting was a lot easier in the classic designer. Had relied on similar code previously but cannot replicate the same on New forms designer. 

1 0
replied on February 2, 2023

That's been a recurring theme here on LFAnswers since 11 Update 3 was released.  People want to do more with the Javascript on the Modern Designer, but they can't.  With the scripts running in a sandboxed iframe like it does, it just cannot access the components of the form directly, only via the very specific functionality that was included in the LFForm object.

1 0
replied on February 2, 2023

I would recommend not using the buttons to signal approve/reject.  Instead use a required radio button field.  Selection of the "reject" radio button shows a required comment field.  The submit then completes the form.

1 0
replied on February 2, 2023

Yes, that was my plan but maynot suit as the query can have multiple loops.  We may lose the initial quiery dialogues if there are more than one query/response loop.

0 0
replied on February 9, 2023
1 0
replied on February 1, 2023

I haven't seen a way to use the Modern Designer JavaScript to set Required as True or False. I tried to figure that out for quite some time. 

You could use a Mulit-line field instead?

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

Sign in to reply to this post.