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

Question

Question

Need Some Help Getting LFForm.onFormSubmission Script to Work as Expected

asked on January 19, 2024

I've just installed Forms 11 Update 5 (11.0.2311.50553) on a test server, and I'm testing the new LFForm.onFormSubmission functionality that was added with the Javascript in the new designer.

I'm trying to have it react differently based on which submission button was clicked, and it sounds like this is possible using the handlerName functionality.

Here's what the Help documentation says:

So I wrote this simple code to try to confirm it was working as expected: 

LFForm.onFormSubmission(function() { console.log('Submit'); }, {handlerName: "Submit"} );
LFForm.onFormSubmission(function() { console.log('Approve'); }, {handlerName: "Approve"} );
LFForm.onFormSubmission(function() { console.log('Reject'); }, {handlerName: "Reject"} );
LFForm.onFormSubmission(function() { console.log('Save Draft'); }, {handlerName: "SaveAsDraft"} );

I was expecting single line to be listed in the console indicating which submission had been clicked.  But unfortunately, no matter which one I click, the console lists all four:

I'm sure I probably just missed some small detail, but I've been struggling to get this simple code working for over an hour now without success.

Any suggestions?

0 0

Answer

SELECTED ANSWER
replied on January 19, 2024 Show version history

As of right now there is no way to determine which button was clicked on submission. I will create an item for this and report back with the ID

This has been released for Laserfiche Cloud and will also be in Laserfiche 12 later this year!

Check out the docs for an example

 
 
 
3 0

Replies

replied on January 19, 2024

It looks like the handlerName is for naming the handler created by that code for reference later rather than identifying the source of the triggered event.

Maybe test the following to see if anything is being passed into the handler function?

LFForm.onFormSubmission(
    function(e) { 
        console.log(e);
        console.log(this); 
    }, {handlerName: "Test"});

However, it seems like this might not be possible yet.

0 0
replied on January 19, 2024 Show version history

I actually had done those tests too, and hadn't gotten anywhere.

But that is what I'm afraid of, that it isn't possible to identify which submission button was clicked...

It's frustating, because in the other LFForm functions, the optional handler object is used to limit the scope of what is being done.  For example         
LFForm.setFieldValues({fieldId: 10}, "hello");         
limits the setFieldValues function to just the field with id of 10.  So based on the Help documents, you would think we can limit the onFormSubmission to specific handlers. crying

0 0
SELECTED ANSWER
replied on January 19, 2024 Show version history

As of right now there is no way to determine which button was clicked on submission. I will create an item for this and report back with the ID

This has been released for Laserfiche Cloud and will also be in Laserfiche 12 later this year!

Check out the docs for an example

 
 
 
3 0
replied on January 19, 2024

Oh bummer - that kills that project for the time being.  sad

Thank you @████████!

0 0
replied on January 19, 2024

That's unfortunate. This is the kind of stuff I was worried about since we can't really do custom workarounds with the sandboxing.

I can't think of any other way to accomplish this at the moment since you need to include the "save as draft" button.

0 0
replied on January 19, 2024

You could use a radio for the submit option and check the value of it on submit for the time being

0 0
replied on January 19, 2024 Show version history

This isn't an urgent one, so I'm not going to do any weird workarounds like a radio button.

But I was trying to address something that I reuse on a lot of forms, so I feel like I'm still stuck using the Classic Designer with this.

I continue to be stuck using the Classic Designer for the majority of my stuff because of functionality like this that I can't replicate in the New Designer.

1 0
replied on January 23, 2024

Hey @████████- just curious if you got this submitted for potential future enhancement?  You said you'd report back with the ID.  Thank you!

0 0
replied on January 23, 2024

I have opened a new item #506239 for this feature. Should be in the next self hosted release, and cloud prior.

2 0
replied on January 23, 2024

Awesome!  Thank you @████████!

 

0 0
replied on April 2, 2024

Which release will this be included with? LF12 not update 5. right?

0 0
replied on April 2, 2024

correct, this feature would not be included in update 5. I hope to include it in 12

0 0
replied on August 22, 2024

I would appreciate this feature.  

In my Classic form I used JS to build a date/timestamp when approved. 

For the New Designer I built a workaround where I call Workflow to get the last action then update the form from Workflow.  
 

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

Sign in to reply to this post.