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

Question

Question

Needing some help in Retrieving values from the checkbox

asked on February 29, 2024

Working on a form to retrieve the multiple values from the checkbox to a single field.

Here is the code i am using. but not able to get the values from the checkbox

var selectedSpecialties = GetFieldValue("SpecialtyField");
console.log('Selected Specialties:', selectedSpecialties);

// Ensure that selectedSpecialties is an array
if (!Array.isArray(selectedSpecialties)) {
    selectedSpecialties = [selectedSpecialties];
}

// Convert the array to a comma-separated string
var combinedSpecialties = selectedSpecialties.join(", ");
console.log('Combined Specialties:', combinedSpecialties);

// Set the value of CombinedSpecialtiesField
SetFieldValue("CombinedSpecialtiesField", combinedSpecialties);

0 0

Replies

replied on February 29, 2024

Your code is mostly there, it seems like you are calling the functions incorrectly. This code should work for you, just update the fieldIds to be the fields you are looking for
 

LFForm.onFieldChange(
  async () => {
    let checkboxValues = LFForm.getFieldValues({ fieldId: 7 });
    if (!Array.isArray(checkboxValues)) {
      checkboxValues = [checkboxValues];
    }
    await LFForm.setFieldValues({ fieldId: 6 }, checkboxValues.join(', '));
  },
  { fieldId: 7 }
);

Full documentation is here

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

Sign in to reply to this post.