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



Forms 11 JavaScript with Collections/Tables

asked on January 19, 2023 Show version history

Hi all,

We've used the new JS library in Forms 11 for a couple of simple bits now, but I'm now looking to use it inside a collection and am struggling a little.

I have a collection which has a single line field populated from a lookup, and if the lookup returns a value I'd like to check a checkbox field on the same row.

I can add the "change" event to the single line and write to the console each time one changes, and set the value of a checkbox at a specified index, however I don't know how to set the index of the current row?

This is my script currently:

  console.log('DB row ID changed');
  LFForm.setFieldValues({fieldId: 53, index: 0}, {value: ["Link_Company"]});
}, {fieldId: 66});

(the single line field ID is 66 and the checkbox field ID is 53. The value of the checkbox I'm setting is Link_Company)

Is there a way to do this?

Thanks in advance!


0 0


replied on January 23, 2023

I've been messing around with this to see if I could find a Javascript solution for this (and a number of other things I've been trying to find solutions for), and I keep hitting the same wall. 

This includes some guesswork, so if I'm wrong, hopefully someone will set me straight. 

With the classic designer, the Javascript is part of the form itself, and thus we can have Javascript (or JQuery) code that functions on any part of the form, and even some other parts of the window outside of the form - we have a lot more control and customization - but also more risk of doing something weird.

With the new designer, as best I can tell, the custom Javascript we are adding are running within an iFrame, so it is effectively an entirely separate website.  And the origin of that iFrame appears to be different than the origin of the main page, so you get cross-origin errors if you try to do something via window.parent.  If I'm right, that is why you can't get any code to work that manipulates fields, their components, or the structure of the form itself - they are just not inside the same frame at all - effectively, not on the same page.  With the form structured this way, any access to components of the form is entirely limited to what exists in the LFForm object which passes the commands over to the main form in the main window.  But if the desired functionality doesn't exist in the LFForms object, we can't handle it more directly with Javascript (at least that I can find).

I'm sure from a security perspective, this is much better.  But from trying to extend functionality with custom code, it's kind of cut us off at the knees.  This is the biggest hurdle for me with the new designer, because if I can't do something with built-in functionality, I always find a way to code it, but that option has been severely limited.

So, bottom-line, I don't think it's possible to do this with the new designer currently.

3 0
replied on January 24, 2023

Hi Matthew,

Sounds like you've been using this a fair bit! And while I haven't looked at it in quite as much depth as you I see the same behaviour. As you said for security etc. this is great, particularly for cloud, but for other aspects it does make things quite difficult.

Does anyone from Laserfiche know if there is a full reference for the LFForms object anywhere which shows all of it's properties? For the collections/tables specifically it would be useful to know what row/index the field you're referencing is at.

While there are a lot of examples in the documentation these mainly relate to copying values between fields (which can be done using calculations rather than JS).


2 0
replied on February 27, 2023 this list is what LFForms object supports currently, we are looking into expand the support based on customers' feedback.

0 0
replied on January 19, 2023

I'd love to know the answer to this too.  I've been messing with it for a while trying to find a solution, and I'm thinking they didn't code it to track the event trigger in a way that you can reference back to it.

0 0
replied on January 19, 2023
LFForm.onFieldChange(function(){ LFForm.setFieldValues({fieldId: 53, index:0}, {value: LFForm.getFieldValues({fieldId: x}))}) }, {fieldId: 66});

Try that. I haven't tested it myself. I am doing something similar with the field labels. field ID x is the field you are calling "Link_Company".

Otherwise, if you just want to set the value "Link_Company"...

LFForm.onFieldChange(function(){ LFForm.setFieldValues({fieldId: 53, index:0}, {value: "Link_Company"}))}) }, {fieldId: 66});

Apologies if my syntax isn't correct. I am learning this new inline JavaScript too. :)

0 0
replied on January 20, 2023

Hi Jonathan,

Thanks for your suggestion, apologies I don't think I was very clear. So this is my collection:

When the field "Database Row ID" (highlighted) is populated I want to check the checkbox "Link Company" (underlined red) on the same row. So in the above case the checkboxes for companies with ID's 1, 2 and 4 should be checked.



0 0
replied on May 26, 2023

Hi Dan,

I know this post is a few months old but I came across the same type of issue and was finally able to get the index for each field in my collection working.   Hopefully this might help!

My fields:
fieldID:35 - this is my collection
fieldID:54 - text string that is set by a database lookup
fieldID:41 - text string that gets updated with subtext


LFForm.onFieldChange( function(e) {

  console.log ("Length - " + (LFForm.getFieldValues({fieldId: 35}).length) );
  for( let i = 0; i < LFForm.getFieldValues({fieldId: 35}).length; i++) {
  	console.log(LFForm.getFieldValues({fieldId: 41, index: i}));
    if ( LFForm.getFieldValues({fieldId: 54, index: i}) === "True") {
      LFForm.changeFieldSettings( {fieldId: 41, index: i}, {subtext: "Security - Public" });
    } else {
      LFForm.changeFieldSettings( {fieldId: 41, index: i}, {subtext: "Security - Private" });
}, {fieldId: 54});


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

Sign in to reply to this post.