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

Discussion

Discussion

LFForm Object - How do you get the entire field but check it's value?

posted on October 27, 2023

The problem with the get field values method is that it just returns an array of values with no way to re-reference the field in any other way, for example changing it's color based on the value you see.

For example if I write this code

var testValues = LFForm.getFieldValues(LFForm.findFieldsByClassName("test"));

I get an array of string values and I can look at them all in a for each loop, but if I see something I where I want to make a change, I can't make a call like $(this) and some jQuery method to work with the field in the moment.

If I use findFieldsByClassName on it's own it appears this returns the entire field rather than just a copy of it's values. However since it does not return a jQuery object we do not have access to $(this) or any of the methods we commonly discuss on answers and outlined in the Javascript documentation from Laserfiche IE: $(this).value(), $(this).attr(), etc.

So how would I get/set the value, attributes, class names, etc for each object returned by the findFieldsByClassName method?

How do we see all the methods available to use to work with the field in common ways we need to in Forms.

Or should I just be converting this array to a jQuery array and go back to what I know?

0 0
replied on November 16, 2023

Unfortunately, a JQuery array would not help you here. I do want to look into simplifying the LFForm API interface, but for now if you take the function

LFForm.findFieldsByClassName("test")

and save this to a variable, you can reuse that in any of the other functions. For example:

 

const testFields = LFForm.findFieldsByClassName("test");
const testValues = LFForm.getFieldValues(testFields);
LFForm.onFieldChange(function() {
    console.log(LFForm.getFieldValues(testFields));
}, testFields);

// . . . etc for any of the LFForm methods

 

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

Sign in to reply to this post.