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

Question

Question

DOMContentLoaded no longer works in latest update

asked on December 11

Hope somebody can help me with the modern forms designer on a self hosted setup.

I have a client running on Laserfiche Forms Professional Version 12.0.2503.10378 where I use "DOMContentLoaded" in the JS to get a token from the URL to be used on the form.

// Get the review uuid (token) from the URL and set it into the Manager Review UUID field
document.addEventListener("DOMContentLoaded", function () {
    const url = new URL(window.location.href);
    let token = new URLSearchParams(url.search).get("token");
    console.log("Extracted token:", token);

    if (token) {
        token = token.trim();

        setTimeout(function () {
            // Target by variable name (preferred for Modern Designer)
            const field = document.querySelector("[data-var='Manager_Review_UUID'] input");

            if (field) {
                field.value = token;

                // Dispatch input event so Forms registers the change
                field.dispatchEvent(new Event("input", { bubbles: true }));
                console.log("Manager Review UUID field set with token.");
            } else {
                console.warn("Manager Review UUID field not found. Check variable name or selector.");
            }
        }, 2000); // 2000 ms = 2 seconds
    } else {
        console.log("Token is empty or not provided.");
    }
});

This code works perfectly in this version of forms, however in the latest version "Laserfiche Forms Professional Version 12.0.2509.20409" on a separate customer's server, the code does not seem to be executing.

1 0

Replies

replied on December 15

None of that code should have ever worked in the modern designer.

  1. You don't need DOMContentLoaded. The code executes when the DOM is loaded so you don't need to wait for anything
  2. You cannot access window.location.href
    1. Access the form URL via pageURL shown in the docs here
  3. Lines 12-18 cannot access form fields that way. 
    1. You can set the field value using the LFForm object which will automatically fire a change event so you don't have to fire it yourself.
0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.