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

Discussion

Discussion

Forms 11 - Javascript

posted on October 6, 2021

We recently upgrades to 11 and I was looking forward to using the new forms interface but noticed there is no way to use JavaScript.  Most of our forms have some JavaScript in them.  With this being the case I have to use the classic version and cannot take advantage of the new version.

Are you able to provide an update as it if/when the new forms interface will have java?

1 0
replied on May 16, 2023 Show version history

Ok, I'm taking a stab at the whole external js file thing. There is a specific example in the help files that I have followed but am getting the following error in the console. Can anyone see what my flaw is?

 

^If  I do that, I get this:


Is there some formatting it is assuming I know to put in the js file or the inline JavaScript editor?

Thanks in advance. Feeling a little 'nooby' over here. I get that the form had to evolve but, dang, I rely on jQuery tremendously. 


 

0 0
replied on May 16, 2023

What do you have in the "External" tab? Could just be a typo or something, but it is hard to say since the screenshot only shows the Internal tab.

As for JQuery, I prefer it especially for delegated event handling, but most things can be rewritten in vanilla JavaScript. My biggest hurdle is the sandboxing since that prevents about 75% or more of my custom implementations from transferring.

0 0
replied on May 16, 2023

Thanks. It is hard to see, but I copied the url path from the help doc:



Yeah, if/when they kill the classic designer I'm going to need a solid 3-4 months to see if I can even have the same functionality as I did with the jQuery. It can get tricky pretty quick when dealing with collections and tables for sure.

0 0
replied on May 16, 2023 Show version history

The documentation seems to imply that this shouldn't be the case, but maybe the inline is executing before the external file is loaded?

I'd say to try running that same line of code from the console after the form is loaded. If it works, it could be a timing/sequence issue, if you get the same error then that would indicate a problem actually loading the external file.

The other problem for testing with the console may be the sandboxing since the new JavaScript approach adds iframes to the mix, and that adds cross origin hurdles which can limit what you can do with the browser console.

If that is the case and you can't really test in the console, then maybe test by adding a significant timeout delay or something like that to the inline.

 

As much as it pains me, if they decided to kill the classic designer with the current state of things, I'd have to move a lot of our processes out of Forms.

I've already started building more standalone web apps since we're very uneasy about starting new projects in what is now the "legacy" designer, and although the new designer is great in many ways, it just can't do what I need it to do to meet stakeholder requirements/expectations.

1 0
replied on May 17, 2023

They have said several times that they have no plans to remove the Classic Designer.  But yeah, it makes me uneasy too.  I've got custom JQuery on 95% of the my processes.

I've got the external script working on Version 11.0.2212.30987 with the example you listed.  

I used some console.log commands to ensure that things were not loading out of order.  Like this:

External File: 

console.log('1');
function changeValue(Id,value){ LFForm.setFieldValues({fieldId: Id}, value); }

 

Code on the Form: 

console.log('2');
changeValue(1,"newvalue");
console.log('3');

 

And it did populate the field value, and the console looks like this:

That doesn't solve the issue, but may help identify what it's doing wrong.  If #1 doesn't show at all, it may not be loading the script.  And if #1 happens after #2 or #3, then it may be loading things out of order.

1 0
replied on May 17, 2023

To rip out the existing Classic Form Designer would be a nightmare for them. They'd have to pick through a decade or more of legacy code and tease apart what elements can be removed without breaking everything else. It's safe to assume the classic designer is here to stay. 

The only realistic concern would be if the classic designer has showstopper bugs after major patches or releases, as most of their development and QA hours will be going into the modern designer going forward from now.

They certainly won't be adding new features or enhancements to the classic designer if they can possibly avoid it. 

1 0
replied on May 17, 2023 Show version history

@████████ I agree. It's extremely unlikely the Classic designer is going anywhere anytime soon, but it definitely won't be getting any major upgrades.

I'd say it is comparable to the .NET situation. Microsoft isn't going to eliminate Framework anytime soon because it's too widely-used. However, even if it is going to be around for a long time it has fallen behind and switching to .NET 6+ is certainly the broader recommendation.

Some may hold out for a while with decent reasons, such as delaying the move away from .NET Framework because of the short life cycle of new .NET versions, or sticking with the Classic Form Designer for JavaScript, but it's inevitable and eventually those older platforms get so far behind they're unusable.

4 0
replied on May 22, 2023

User error. I didn't create the custom folder:

https://{yourFormsServerFullQualifiedName}/forms/js/custom/external.js

3 0
replied on March 16, 2023

Thank you Houng. Now I understand the why. Very well explained.

Are there plans to have a way for us end users to request customizations to the LFForm object?

For ex: Currently I am trying to get the multiline object to expand without scroll bars; so that, when the form is saved as a PDF the entire entry will be available for viewing. 

0 0
replied on January 12, 2023 Show version history
0 0
replied on March 15, 2023

It looks like jQuery is not available in the new designer. Is that right? 

0 0
replied on March 15, 2023

Not by default.

Via the "External" tab you can add the JQuery libraries, including the ones that are already installed for Forms.

But bear in mind that any Javascript you add to the new designer, including anything you add on the "External" tab, runs within a sandboxed iFrame, so it doesn't have direct access to the form, fields, window, or document.  Even if you add JQuery, you'll still be limited to changes on the form that are available through the LFForm interface.

3 0
replied on March 15, 2023

What is Laserfiche's reasoning to using the iFrame and keeping us from direct access to the form, fields, window and document?

Why not have the same functionality as in the classic designer. Seems like that's going backward.

Would be nice to understand.

 

2 0
replied on March 15, 2023

Hello,

There are 2 main reasons for putting custom scripts in sandbox iframes and limiting changes to what LFForm offers:

1. Allowing direct access to the DOM opens Forms up to security vulnerabilities. Having direct access to the DOM means you also have access to all cookies and local storage. If you are under an XSS attack or you open a form with malicious code, your credentials can be used to call APIs to do unwanted things, like deleting processes or updating security roles. 

2. Classic form uses the DOM as the source of truth, so you can directly modify things on the DOM and they will stick. New form uses Angular with an internal source of truth. So unless you modify this source of truth, Angular will overwrite any changes you make on the DOM. You can only modify this source of truth through the LFForm API.

We understand that these restrictions to scripting in new form make it harder to do what you did with scripting in classic form. We are constantly collecting information on scripting use cases and will expand the LFForm API to accomodate them. We will also update the documentation to help ease migration through more concrete examples. 
Last but not least, as a sneak peak, we are working on a new feature that lets you define your own field on the form. You will have full access to your custom field for scripting purpose.

6 0
replied on March 16, 2023

Huong, if it helps your team the thing I most often have to use JavaScript for is date calculations, taking a date or set of dates from fields on the form, using the JavaScript Date objects to do things the Advanced Formula can't do, and then putting a value into a field or values into a drop down. 

The other thing I have to use JavaScript for is to create tables with a 'select row' checkbox. This is where the lack of jQuery hurts, because I need to use the jQuery element selectors to get at the 'Select Row' checkboxes in a table. 

0 0
replied on March 16, 2023

Thank you @████████- I suspected that was the reasoning, but it is nice to have confirmation from Laserfiche regarding it.  I agree that it is a really good reason to restrict it - especially for publicly available forms.  Personally, I'm finding myself using the New Designer most with public facing forms that I want to look and feel nice on any browser, but don't need really complex functionality.  But there are definitely some areas where the LFForm interface needs to be expanded.  

Meanwhile, I continue to use the classic designer almost exclusively for internal forms for staff, which often need additional or more complex functionality.  Especially since I'm making use of API calls and other really complex stuff.

Also, I am really wishing the new Field Rule functionalities that came with 11 Update 3 were included in both designers instead of just the new one.  I can do all that stuff with Javascript in the classic designer, but it is so much easier to do with Field Rules.  

2 0
replied on March 16, 2023

@████████

Unless I'm mistaken, this should be possible with the current LFForm API.

Based on my understanding, you can use the LFForm API to retrieve the field value(s), perform the necessary calculations, then use the LFForm API to set the appropriate field values.

3 0
replied on May 17, 2023

Oh yes the date calculation thing is easy enough. Or at least as easy as date calculations get. 

Manipulating data in tables has been an exercise in frustration. At this time the LFForms object doesn't support setting values in tables or collections. 

1 0
replied on May 17, 2023

Also, the classic trick of getting at HTML elements by going into the web dev tool and picking out specific items doesn't work any more, as everythig on a modern form is inside DIV or SPAN tags. 

It was super frustrating to discover a modern designer drop down field is done with SPAN and DIV tags with some kind of code in the backend. 

0 0
replied on May 17, 2023

Hi @████████ can you talk a little more about what you are trying to do with dropdowns, and your "select row" checkbox option?

As for setting fields in tables, one thing to be weary of is adding rows to a table or collection returns a promise so you need to properly await it before setting. See this example below:


 

const modernScript = async function() {
  const collection = { fieldId: 35 };
  const fieldInCollection = { fieldId: 38 };
  await LFForm.addRow(collection, 3);
  await LFForm.setFieldValues(fieldInCollection, [1,2,3])
  const newFields = LFForm.getFieldValues(fieldInCollection);
  await LFForm.setFieldValues({ fieldId: 47 }, newFields.join(', '));
}
// NOTE: no await here
 modernScript();

 

1 0
replied on May 18, 2023

I'm trying to get a list of classes, and then a pulldown next to each with a pulldown for available times appended to 'Select a time to register' and use the set value to make 'Select a time to register' be the default value. 

I was only trying to do that because choosing that as the default value in the properties in form designer didn't work. 

This doesn't work in either the modern or classic designer to make the default value 'Select a date' 

So I have to use this in classic designer, because LFForms object can't set values in tables or collections. 

$(document).on("onloadlookupfinished", function(event) {
  $('.form-item-field').val('Select a date').attr("selected", "selected");
});

0 0
replied on May 18, 2023

Can you confirm which version of Laserfiche Forms you are using? The LFForm object can update fields in tables/collections.

const modernScript = async function() {
  const collection = { fieldId: 35 };
  const dropdownInCollection = { fieldId: 48 };
  await LFForm.setFieldValues(dropdownInCollection, "Select a Date");
}
// NOTE: no await here
modernScript();

I will definitely file a bug for the default value not being respected when append choices to lookup values is selected as I can reproduce that.

1 0
replied on May 18, 2023

That is definitely something that needs to be fixed because in the next few lines it shows you how to update tables with setFieldValues.

 

Dropdown default issue has been filed #426628
Documentation bug has also been filed 

1 0
replied on October 6, 2021

They are working on JavaScript functionality now. No ETA yet, just "Coming Soon"

Forms Designer Comparison (laserfiche.com)

1 0
replied on October 7, 2021

Thank you for the link.  Seems like a pretty important component to not have available at release.  

0 0
replied on December 28, 2021

I have not upgraded yet, but I'm curious.  Is the choice for which designer to use something that is universal through the server or decided on a case-by-case basis for individual processes or forms?

0 0
replied on December 28, 2021

@████████ it's case-by-case. When you add a new form (or a new business process with Form submission/approval selected) you can choose which designer to use, and you do seem to be able to mix-and-match within a process.

2 0
replied on December 28, 2021

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

With so much custom Javascript on so many of my existing forms, the last thing I want is everything to break when we do upgrade to 11.

0 0
replied on December 28, 2021

No problem. They definitely set it up to allow for a gradual transition.

Not only do you still have the classic designer option, but forms made with the classic designer are only converted if you explicitly click the Convert button.

Additionally, when you Convert a form, it creates a separate copy and keeps the original until you delete it, so there's less risk involved.

1 0
replied on December 28, 2021

Oh wow!  That's a relief.

0 0

Forms 11 JavaScript in the new designer

Sign in to reply to this post.