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

Question

Question

Assistance with LFForm Disable Field Object

asked on May 31, 2024

Hello,

I'm reaching out to see if anyone can help with targeting a specific checkbox within a field in the new Form Designer. Here are the methods I've tried:

LFForm.disableFields({ fieldId: 54-0 });

This method disables all checkboxes in the field, although it's meant to target the first checkbox.

LFForm.disableFields({ fieldId: 54, index: 0 });

This one returns an error, indicating the field can't be found.

Is it possible to target a specific checkbox? Thanks!

0 0

Replies

replied on May 31, 2024

Additionally, I tried the following method based on the element's id obtained through the inspect element tool:

LFForm.disableFields({ fieldId: Field54-0 });

The element displays its id as:

<input _ngcontent-anq-c231="" type="checkbox" id="Field54-0" value="Business_Officer" data-index="0" class="ng-wrapper-invalid ng-untouched ng-pristine ng-valid">

Unfortunately, this method also returns an error indicating that the field is not defined.

0 0
replied on May 31, 2024

I'm pretty sure that you can't disable specific checkboxes within a checkbox field, just the field as a whole.  This is the case with both Field Rules and the LFForm interface via Javascript.

I have a form that needed this functionality, and I ended up making four different checkbox fields, with CSS to make them look more like a single field.  The tricky part doing that is handling required status on the fields since they are not grouped together - but if you are patient and careful, you can make it work with Field Rules.

0 0
replied on May 31, 2024

That's unfortunate... this seems like an oversight of the LFForm Disable Field Object and Field Rules. I'll likely stick with the Classic Form Designer until something like this becomes available. I appreciate the workaround though!

0 0
replied on May 31, 2024 Show version history
LFForm.disableFields({ fieldId: 54, index: 0 });

 This is a good format. My initial thought may be there are asynchronous functions like adding / deleting rows (ex: LFForm.addrow()) that may be interfering with this. If it is an order of operations issue like this, it can be solved using the "await" and "async" keywords. 

 However, I've also had difficulty using certain methods that seem finnicky. 
 
Example: I had two collections:
- Collection1: A fixed Length of 1
- Collection2: Can append to include however many rows.

This code worked great on collection 1:

 const _Collection1 = { fieldId: 20 }
 LFForm.changeFieldSettings(_Collection1, {CSSClasses : "denied"})

However, with Collection 2 I had to get more creative and relay each field in each row, rather than apply CSS to the row:

const _Collection2Row1 = {fieldId: 10}... // same for Rows 1 through 10
const _Collection2Rows = [_Collection2Row1, Collection2Row2..., Collection2Row10]

 _Collection2Rows.forEach(f => LFForm.changeFieldSettings({fieldId: f['fieldId'], index: i}, {CSSClasses : "denied"}))

I really prefer using Code over Field Rules whenever possible (but there are some cases, like NOT saving data on hidden fields or LookupRules when I have to compromise). Hopefully this puts you on the right track, but when I get a second to play around I'll see what I can find. You could even try LFForm.hideFields() + clearing with LFForm.setFieldValues() potentially.

0 0
replied on May 31, 2024 Show version history

When you refer to something like "{ fieldId: 54, index: 0 }" - the index is referring to the field in a table or collection.  So this is saying field 54 in the 1st row (index counts up from 0) of the table.  This does not refer to individual input elements within the checkbox field.

"LFForm.disableFields" is going to target the entire field, not individual checkboxes within it, disabling/enabling individual checkboxes within the field is not possible with current functionality.

The reason that your code examples worked different in a collection with 1 row versus many rows is because when there is only 1 row, it's dealing with a single element or value, but when there are more rows, it's now a full array, so how you address and target the fields changes.

1 0
replied on May 31, 2024

I see, I missed the individual "checkbox" part.

Closest thing in LFForms would be to have an Auto Uncheck function and perhaps a warning label for the specific field specifying the selections disabled, depending on User experience.

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

Sign in to reply to this post.