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

Question

Question

Referencing a field in Javascript

asked on May 9, 2024

Hi all, 

 

I'm trying the new Javascript in the modern designer.

 

I'm just trying to do something by setting my field (test_line) to have a new value of "New Value" as in the instructional docs. However, it does not seem to be working. Have also tried referencing my field as #q5 as its id is 5.

What am I missing here?

 $('#5 input').val('New Value');

Trying to follow along here

https://doc.laserfiche.com/laserfiche/en-us/Content/Forms-Current/Javascript-and-CSS/Customizing%20a%20Form%20with%20CSS%20and%20Javascript.htm

Thanks

0 0

Answer

SELECTED ANSWER
replied on May 9, 2024

The code example you included there from the Classic Designer is written using JQuery, and the Modern designer no longer natively includes JQuery support.

Additionally, the Javascript in the Modern designer runs within a sandboxed iFrame that doesn't have direct access to the form and fields in the way that the Classic designer did, so it can't target the form elements directly via the DOM like that.

The ability to manipulate fields and their contents in the Modern designer Javascript is all managed via the LFForm interface and its various functions, which are detailed in the help documentation (this link if you are self-hosted: https://doc.laserfiche.com/laserfiche.documentation/11/administration/en-us/Default.htm#../Subsystems/Forms/Content/Javascript-and-CSS/JavaScript-in-the-Forms-Designer.htm)

This code from the Classic Designer: 

$('#q5 input').val('New Value');

 

Can be replaced by this code in the Modern Designer: 

LFForm.setFieldValues({fieldId: 5}, "New Value");
1 0

Replies

replied on May 9, 2024

Fantastic, thanks Matthew, much appreciated.

I will continue my learning from that documentation link. Appreciate the push in the right direction.

 

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

Sign in to reply to this post.