how to trigger on change event using LFForm object in modern forms
Question
Question
Replies
Any change to the field value, including changes via Javascript, should trigger the event.
But it sounds like you are asking about triggering the event without actually changing the value - which unfortunately, I don't think is possible.
I have one form where I getthe field value and store it in a variable, clear it from the field (which triggers the change event), and then put the value back into the field (which triggers the change event again).
Depending on what you're trying to do, something like this should work:
LFForm.onFieldChange(function() { if (LFForm.getFieldValues({fieldId: 33}) === "Option 1") { LFForm.changeFormSettings({title: "Title 1"}); LFForm.changeFormSettings({description: "Form Description 1"}); LFForm.changeFieldSettings({fieldId: 30}, {label: "Field Label 1"}); LFForm.changeFieldSettings({fieldId: 8}, {placeholder: "Placeholder 1"}); } else { LFForm.changeFormSettings({title: "Title 2"}); LFForm.changeFormSettings({description: "Form Description 2"}); LFForm.changeFieldSettings({fieldId: 30}, {label: "Field Label 2"}); LFForm.changeFieldSettings({fieldId: 8}, {placeholder: "Placeholder 2"}); } } , {fieldId: 33})
Just change the field ID's to the field you're wanting to watch (33, x2), and the fields you're wanting to update (30 & 8). Then repeat the lines as necessary to account for any additional fields.
I am trying to set a custom HTML field via LFForm, how do I do that?
You can't use alert() in the Layout Designer like you can in the Classic Designer - but you can still use console.log().
Changing a Custom HTML field is done via the LFForm.changeFieldSettings function and editing the "content" of the field. This is the example from the LF11 Help Documentation:
LFForm.changeFieldSettings( {fieldId: 12}, {content: "<a src='https://www.laserfiche.com'>Laserfiche</a>"} );