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

Question

Question

LFForm.changeFieldOptions not working with variableName in Modern Forms

asked on April 18 Show version history

Hi all,

I've come across this issue in Modern Forms in Laserfiche Forms 11 Update 5. I have a table, with a variable called "Customer", with at least one row added. I want to add a new customer to the dropdown with a variable I defined as fullName. I'm able to get the form to add fullName to the dropdown list if I use fieldId, but not variableName.

I am able to use variableName when getting values from the single-line text boxes First_Name and Last_Name, however.

var fullName = LFForm.getFieldValues( { variableName: "Last_Name" } ) + ", " + LFForm.getFieldValues( { variableName: "First_Name" } );

 

// WORKS

LFForm.changeFieldOptions( { fieldId: 28 }, [{label: fullName, value: fullName, selected: true}], "add" );

 

// DOES NOT WORK

 LFForm.changeFieldOptions( { variableName: "Customer" }, [{label: fullName, value: fullName, selected: true}], "add" );

 

This is the error I get when I use variableName:

about:srcdoc:32 Uncaught Error: Unable to find field. Please check your ID.
    at Object.changeFieldOptions (about:srcdoc:32:4972)
    at window.addOffender (eval at window.init (about:srcdoc:17:33), <anonymous>:12:10)
    at eval (eval at <anonymous> (about:srcdoc:1:2404), <anonymous>:3:1)
    at about:srcdoc:32:2459

 

Does this mean that LFForm.changeFieldOptions() doesn't support variableName? It's not very clear in the documentation.

 

EDIT: I also tried this and it returned null. Is this a bug then?

var customerFields = LFForm.findFieldsByVariableName("Customer"); // customerFields = null

0 0

Answer

APPROVED ANSWER
replied on April 20 Show version history

variable names for fields in a table aren't set in an expected manor as the actual variable name includes the table name in it. I recommend using the field id for these fields and your code will work fine.

 

If you start your script with an object and define it like follows, you can have a human readable variable used in your script that works in all LFForm functionis

// Define all form field IDs
const formFields = {
  firstName: { fieldId: 1 }
};

// Use them in your code anywhere
LFForm.getFieldValues(formFields.firstName);

 

1 0
replied on April 22

Hi Zachary, thanks for the clarification. I'll go the const route as it's much more readable.

Can we also get the documentation updated with the recommendation to use fieldId? It would reduce the confusion when people are working with tables vs everything else.

Thanks,

Christian 

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.