Does anyone have ideas on how to make this JS work in the Laserfiche Forms Modern Designer? It is supposed to limit the "Other" field length to 10 and show a message.
const fields = LFForm.findFields(f => ["Checkbox", "Radio", "SingleLine", "MultiLine"].includes(f.componentType) ); fields.forEach(f => { let fld = LFForm.findFieldsByFieldId(f.fieldId)[0]; LFForm.onFieldChange(() => { ValidateOtherField(f.fieldId); }, fld); }); function ValidateOtherField(checkboxId) { let fld = LFForm.findFieldsByFieldId(checkboxId)[0]; let fieldVal = LFForm.getFieldValues({ fieldId: checkboxId }); if (fieldVal.otherChoiceValue && fieldVal.otherChoiceValue.length < 10) { let subtext = `<b>${fieldVal.otherChoiceValue}</b> was longer than the maximum number of characters and has been removed.`; // Set the note below the field LFForm.changeFieldSettings(fld, { "subtext": "Note" }); // Clear OtherFieldValue, deselect fieldVal.value.pop(); fieldVal.otherChoiceValue = ""; LFForm.setFieldValues(fld, fieldVal); }
Screenshot: