LFForm Read API
The LFForm object provides a global interface for accessing Laserfiche form elements and events using JavaScript. Through simple functions, you can find a specific field, retrieve the field values, and update field contents. You also have access to events both at the individual field level as well as the form submission event.
API References
Dive deeper into specific areas of the LFForm API:
-
Read API
Learn how to retrieve field values and find fields.
-
Write API
Discover how to modify fields and handle operations.
-
Events API
Subscribe to and handle form, field, and lookup events.
-
Properties API
Understand runtime form properties and state.
Additional Resources
-
Recipes
Learn more about common patterns and solutions.
-
Custom HTML guide
Check out our custom HTML and sandbox integrations.
Example
const formFields = {
firstName: { fieldId: 10 },
expenseAmountColumn: { fieldId: 31 },
};
const firstName = LFForm.getFieldValues(formFields.firstName);
const firstRowAmount = LFForm.getFieldValues({ fieldId: 31, index: 0 });
const required = LFForm.findFields((f) => Boolean(f.settings?.required));
const idMatches = LFForm.findFieldsByFieldId(10);
const classMatches = LFForm.findFieldsByClassName('blue');
Identification Objects
Identification objects are objects containing information identifying which fields the interface should act on. Identification objects can have the following properties:
- trackId: A unique identifier for a field. Note that the trackId is generated on field
creation, so it won't be the same between different submission events.
Example: {trackId: "59783b47-db11-4709-ba5a-1fb4833a1f73"}
- fieldId: The field ID of a field.
Example: {fieldId: 1}
- variableName: The name of the variable associated with the field.
Example: {variableName: "First_Name"}
- variableId: The id of the variable associated with the field.
Example: {variableId: "e7c9e10c-eeb0-4ce2-b3c6-26264c7fe655"}
- index: If the field is in a collection or table, you can specify the index to get the exact
field.
Note: The index starts from 0.
Example: {fieldId: 2, index: 2}
Note: In all LFForm interfaces, you can specify an array of identification objects instead of
just one object to target multiple fields.
Example: LFForm.getFieldValues([{fieldId: 2}, {fieldId: 3}]).
getFieldValues
Gets the value of the specified fields.
- Signature: LFForm.getFieldValues(id)
- Input:
- id: An identification object or array of identification objects that have the desired fields.
- Output:
- If there is only one field matching an identification object, returns the data of that field.
- If there are multiple fields that match an identification object (fields in a collection or table, for instance), returns an array of data for all matching fields.
Examples:
- For a single line field with a field ID of 10 and the current value of "Hello":
- LFForm.getFieldValues({fieldId: 10}); // returns "Hello".
- For a repeatable field (table or collection) with 3 rows, where each row has a single line field with a
field ID of 10; in row 1, the single line field has the value "a"; in row 2, the single line field has
the value "b"; and in row 3, the single line field has the value "c":
- LFForm.getFieldValues({fieldId: 10}); // will return a string array of ["a", "b", "c"].
- LFForm.getFieldValues({fieldId: 10, index: 0}); // will return "a".
findFields
Finds any fields that satisfy the specified arbitrary conditions.
- Signature: LFForm.findFields(predicate)
- Input:
- predicate: A function that takes in the field State and should return true for fields you want to find, and false for fields you don't want to find.
- Output:
- An array of fields that satisfy the predicate.
Examples:
- LFForm.findFields(f => f.settings.label === "First Name"); // Finds all fields whose label is "First Name".
- LFForm.findFields(f => f.settings.required); // Finds all required fields.
findFieldsByClassName
Finds fields with the specified CSS class.
- Signature: LFForm.findFieldsByClassName(className)
- Input:
- className: The CSS class that is assigned to the fields you want to find.
- Output:
- An array of fields with the specified CSS class.
Example:
LFForm.findFieldsByClassName("blue");
findFieldsByFieldId
Finds the fields with the specified field ID.
- Signature: LFForm.findFieldsByFieldId(fieldId)
- Input:
- fieldId: The field ID of the fields you want to find.
- Output:
- An array of fields with specified field ID.
Example:
LFForm.findFieldsByFieldId(2);
findFieldsByVariableName
Finds the fields with the specified variable name.
- Signature: LFForm.findFieldsByVariableName(variableName)
- Input:
- variableName: The variable name of the fields you want to find.
- Output:
- An array of fields with the specified variable name.
Example:
LFForm.findFieldsByVariableName("Single_Line");
findFieldsByVariableId
Finds the fields with the specified variable ID.
- Signature: LFForm.findFieldsByVariableId(variableId)
- Input:
- variableId: The variable ID of the fields you want to find.
- Output:
- An array of fields with the specified variable ID.
Example:
LFForm.findFieldsByVariableId("90e0b201-5268-4ace-9f65-8ac32d12b58a");