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

Question

Question

Dynamically Created HTML Disappears When Form Is Saved To Repository

asked on December 5, 2024

I have JS in a form that runs like this:

LFForm.onLookupDone(async () => {
    ...
    LFForm.changeFieldSettings({fieldId: ID}, {content: `<span style="border-bottom: 1px solid #163f65; padding-bottom: 2px; line-height: 1.75;">${varText}</span>`});
    LFForm.changeFieldSettings({fieldId: ID}, {CSSClasses: footer"});
}, {lookupRuleId: 1});

It dynamically adds a footer to a form based on variables that load into hidden fields from a lookup rule. It is working fine but we noticed that when the form is saved to the repository that the custom HTML field that we add this to is just completely blank. How could we make this not disappear when saved to the repository? Is there a CSS class or something to do with @media?

0 0

Answer

SELECTED ANSWER
replied on December 6, 2024

Try something like this: 

const htmlField = LFForm.findFieldsByFieldId(ID)[0];

const makeHtml = async function () {    
    try {
        // Get the field values. Either change these to the correct field ID
        // or use the variableName selector
        let test1 = LFForm.getFieldValues({fieldId: ID});
        let test2 = LFForm.getFieldValues({fieldId: ID});


        // Create the updated HTML content
        const html = `<p><strong>This is a sample footer for ${test1} and ${test2} </strong></p>`;

        // Update the Custom HTML fields with the new content
        await LFForm.changeFieldSettings(htmlField, { content: html });
    } catch (error) {
        console.error('Error updating HTML fields:', error);
    }
};

// When SQL lookup is complete, update the Custom HTML
LFForm.onLookupDone(function () {
    makeHtml();
}, {lookupRuleId: ID}); // Adjust the lookupRuleId accordingly

// Run on page load (needed for the Save to Repository task)
makeHtml();

I use something similar for embedding test scores in tables or dynamic dates for form windows and it prints on the generated PDF.

 

 

 

4 0
replied on December 9, 2024

This worked, thank you!

0 0

Replies

replied on December 6, 2024

You may try pushing the lookup value into a hidden field (make sure to save/keep the value of the hidden field) and use the hidden field value to populate the HTML.

 

Since the HTML is dynamic, it has to be loaded each time the form is loaded and the lookup only happens the first time the form is loaded.

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

Sign in to reply to this post.