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

Question

Question

Forms 11 custom HTML Field Values from a lookup

asked on November 17, 2023

I know previously, LF Forms could not populate field values in a custom html if the form is live.  Is that still the case?  If so, is there a way to get the values to show in the modern designer?  

0 0

Answer

SELECTED ANSWER
replied on November 17, 2023

Yes, that still holds true. The reason is you are using a variable to populate the custom html field, but the value for the variable does not get set until the form is submitted or if Workflow populated the value to start the instance. You might be able to use JavaScript to accomplish this.

0 0

Replies

replied on November 17, 2023

Do you mean before the form was submitted? 

0 0
replied on November 17, 2023

Correct.  For example, a unique link that is using a lookup.

0 0
SELECTED ANSWER
replied on November 17, 2023

Yes, that still holds true. The reason is you are using a variable to populate the custom html field, but the value for the variable does not get set until the form is submitted or if Workflow populated the value to start the instance. You might be able to use JavaScript to accomplish this.

0 0
replied on November 17, 2023

That is what I assumed.  Thank you!

0 0
replied on November 17, 2023

We use spans to make this work. Here's an older Answers post that talks about that method:
https://answers.laserfiche.com/questions/173809/How-to-add-variable-to-custom-HTML

I'm not sure if anyone on our team has done this with the Modern Designer yet, but it does work in the Classic Designer.
 

0 0
replied on November 17, 2023

There is no way to populate a custom html via lookup directly. Like other commenters noted, you can use variables in your custom html to dynamically alter its content, but it will be static on page load and will not update if variables are updated while the form is filled out. We do have a feature item being designed right now that will make this possible.

In the meantime, you can use custom js to fill in your html field. For example:
 

const htmlField = LFForm.findFieldsByVariableName('My_HTML_Field');
const makeHtml = async function (link) {
  if (link === '') return;
  const html = `<div>
    <a href="${link}">Click Here!</a>
  </div>`;
  await LFForm.changeFieldSettings(htmlField, { content: html });
};

const main = async () => {
  // Field that will contain the text needed to create the html
  const myField = LFForm.findFieldsByVariableName('My_Field');
  // Get and set the html with the current value of the field on page load
  const linkText = LFForm.getFieldValues(myField);
  await makeHtml(linkText);
  // any time the field changes, update the html
  LFForm.onFieldChange(async () => {
    const linkText = LFForm.getFieldValues(myField);
    await makeHtml(linkText);
  }, myField);
};
main();

 

0 0
replied on November 17, 2023

Will this one work on Modern Designer?

0 0
replied on November 17, 2023

Yes this code will work on the modern designer!

0 0
replied on November 29, 2023

Hey Zachary, I don't see where you can specify a variable name for the Custom HTML. Can you help me understand line 1:

const htmlField = LFForm.findFieldsByVariableName('My_HTML_Field');

Or, could you upload your example so I can import it please?

1 0
replied on December 7, 2023

That is my bad, you cannot locate a custom html field by variable name because it does not have a variable attached to it, you may use any of the other find fields function in place on that line and the rest of the code will work.

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

Sign in to reply to this post.