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

Question

Question

Lookup populating field does not kick off java script

asked on January 23, 2024

I am very new to Java Script / JQuery and would like some help please.

  • I have a form where the user clicks on a check box.
  • Once clicked 2 fields (New Vehicle & New Company) displays with field rules.
  • The use selects a vehicle registration number from the drop down field "New Vehicle"
  • Forms lookup then populates the "New Company" field with a company name.

My JQuery script kicks off when the check box is clicked and populates another empty single line field based on certain conditions.

The issue I am having is that the JQuery code does not run when the lookup populates the "New Company" field with a value, but when I manually enter the value, the code executes as expected.

After Lookup

After Manual Entry

//User clicked on edit
    $(".evehicle").click(function () { 
        var checkEdit = $(".evehicle :checked").val();
          var nCompany = $(".ncompany input").val();
        if ((checkEdit == "Yes") && (nCompany == "XXXX" || nCompany == "YYYYY")) {
          $(".frule input").val("Show")
        }
      else if ((checkEdit !== "Yes") && (com == "XXXX" || com == "YYYYY")) {
       console.log("Value of company edit uncheck: " + com);
          $(".frule input").val("Show")
        }
      else if (checkEdit == "Yes")  { 
            $(".ncompany").change(function () { 
                var newCompany = $(".ncompany input").val();
              
              if ((newCompany == "XXXX" || newCompany == "YYYYY") && (checkEdit == "Yes"))  {
                $(".frule input").val("Show");
              } 
                  else { 
                    $(".frule input").val("Not Show");
                } 
            });
        } 
          else { 
                $(".frule input").val("Not Show");
            } 
    });

 

0 0

Answer

SELECTED ANSWER
replied on January 24, 2024

Lookups populating a field value do not trigger the change event on that field, you would need to leverage the various lookup events that Laserfiche has set-up.  lookupstarted, lookupcomplete, and onloadlookupfinished. 

$(document).on("lookupcomplete", function (event) {
  alert ("Lookup Complete - Triggered by: " + event.triggerId);
});

 

This should give you a pop-up any time a lookup finishes on your form, and reference the field that triggered the lookup (not the field that was populated, but the field that triggered the lookup to happen).

This should get you started on creating code that acts when the lookup is complete.

1 0
replied on January 24, 2024

Thank you Matthew.

I added trigger events after the change as and JS updated my fields as expected.

I also had to added trigger events after the field update for the Forms field rules to kick off.

1 0

Replies

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.