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



How to use foreach after lookuptablefinished in new design form?

asked on June 17


I'm using the new form design and I'm confused about the javascript part.

All my old scripts no longer work with the new design.

I have a collection that I load via a database. In this collection, I have a "name" field and I have HTML. In the HTML, I want to create a link whose url will be the value of the "name" field.

How do I do this?
Thanks in advance.

0 0


replied on June 18

Hi Olivier, 

"Pure" javascript doesn't work in the new forms designer. It not broken - it's by design. You need to use the LFForm object. LFForm object info here

I have scripted something like this before. This code block fires after the lookup event. The event number of the lookup is shown in your lookup rules (e.g 1 or 2 or 3...whichever number it is). 


LFForm.onLookupDone(function () {
	var link = LFForm.getFieldValues({fieldId: 12});

		{ fieldId: 15 },
		{ content: "<a href='"+link+"' target=\"_blank\" class=\"GFG\">Click Here to Make A Secure Payment</a>" }
		//{ content: "<form action='"+link+"'><input type=\"submit\" value=\"Go to Google\"></form>" }
}, {lookupRuleId: 1}); // after lookup rule 1 is done

After the lookup is done (rule 1) this event fires. 

In this particular code block, I am creating a link from a field (#12)

After I get that link I put it into a variable ("link"), the next step is to change the field settings of my html field (which changes the content of the html field.

My html field is id # 15 and the "changeFieldSettings" event changes my html field. 


I edited this down from a larger function so hopefully I cleaned it up enough. 

2 0
replied on June 18

For what it is worth, the onLookupDone event fires when the rule is complete, it does not guarantee the fields actually have values yet. If you only care about fieldId 12 you should just use the onFieldChange event.

2 0
replied on June 18

Thank you, Zach. Thanks for pointing that out. In my case field 12 was a hidden field with a default value. 

Order of event firing is really important and I am always confused by it. My code is often littered with 'console.log' markers to figure out who's firing when!

1 0
replied on June 18

That does make it trickier, but in that case onlookupdone is a valid mechanism for performing the link creation!

It is also worth noting a few of the LFForm APIs return promises so the function immediately returns before the work is actually committed to the form. In your example you dont really need to await the changeFieldSettings call because you aren't doing any work after it but if you were setting a value or adding rows to another table you would want to await it so you guarantee the change is made before moving forward with your code.

Regardless, I use console.log plenty as well!

2 0


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

Sign in to reply to this post.