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

Question

Question

How to change radio button labels using LFForm

asked on February 6

Hi Laserfiche Network,

I am working on Laserfiche Cloud and I am seeking a method to change the label of radio button choices using LFForm once a specific field event occurs. I have successfully changed form labels and field labels using "LFForm.changeFormSettings" and "LFForm.changeFieldSettings," but I am encountering difficulty in changing the labels of the radio button choices.

Below, you can see the code I am using to change labels. As mentioned, changes to the title and field label (including the radio button label) work, but not to the choice labels of the radio button.

For reference:
FieldId:1 is a Drop-Down field labeled "Language," which includes two choices: "English" and "Spanish."
Using LFForm.onFieldChanges, I would like to switch all the labels from English to Spanish and vice versa each time fieldID 1 changes.

FieldID:25 is one of the radio buttons of the quiz

I would appreciate it if you could review my code and provide some advice on how to achieve this.

Thank you in advance for your assistance.

Regards,

 

Miguel

// Code
LFForm.onFieldChange(function() {
    if (LFForm.getFieldValues({ fieldId: 1 }) === 'English') {
        LFForm.changeFormSettings({ title: "First Aid Quiz" });   // this line works
        LFForm.changeFieldSettings({ fieldId: 25 }, { label: "1.Signs of a chest injury" });   // this line works too
        LFForm.changeChoiceSettings({ fieldId: 25, choiceValue: "1" }, { label: "Anxiety, and fear" });   //this line doesn´t work
        LFForm.changeChoiceSettings({ fieldId: 25, choiceValue: "2" }, { label: "A slow pulse" });    //this line doesn´t work
        LFForm.changeChoiceSettings({ fieldId: 25, choiceValue: "3" }, { label: "Painful breathing" });    //this line doesn´t work
     
    } else {
        LFForm.changeFormSettings({ title: "Prueba de Primeros Auxilios" }); // this line works
        LFForm.changeFieldSettings({ fieldId: 25 }, { label: "1. Signos de lesión en el pecho" }); // this line works too
        LFForm.changeChoiceSettings({ fieldId: 25, choiceValue: "1"}, { label: "Ansiedad y miedo" }); //this line doesn´t work 
        LFForm.changeChoiceSettings({ fieldId: 25, choiceValue: "2"}, { label: "Un pulso lento" });  //this line doesn´t work
        LFForm.changeChoiceSettings({ fieldId: 25, choiceValue: "3" }, { label: "Respiración dolorosa" }); //this line doesn´t work
    }
}, { fieldId: 1 });

code.JPG
code.JPG (113.5 KB)
0 0

Replies

replied on February 7 Show version history

Maybe Cloud has functionality that hasn't been introduced in On Prem yet - so I could be wrong - but I don't think the LFForm interface has the ability (yet) to change labels on checkboxes, radio buttons, or dropdown fields.

0 0
replied on February 7

You can because it is done in this video:

replied on February 7 Show version history

@████████ - I've watched that video twice and played with both the files that are included in the link, and neither of them impact the labels for choices on radio buttons, checkboxes, or dropdowns.  In fact, the "Sample" form has both a radio button field and a drop-down field, and their options remain in English when the language is changed.

The Help Files about the LFForm interface don't include the choice labels on those fields as part of the information that it lists can be changed in the changeFieldSettings function.

EDIT TO ADD: I think the comment this was replying to was deleted?

0 0
replied on February 7

@Blake Smith, @Matthew : that's what I thought, - as you noticed, It islikely that Laserfiche Cloud (using LFForm) doesn't include code for radio button choices label changes, but I would like this to be confirmed. As you noticed there is not reference on laserfiche Cloud documentation. Thank you for your time on it.

0 0
replied on February 8 Show version history

It is not currently available for Laserfiche Cloud. It can be done with self-hosted by using the setFieldValues, since the options for radio buttons, dropdown, and checkbox fields are not labels. If you do change the values though, you would probably want to change them back on form submission and take into account in your gateways and possible workflows that would kick off for the multiple language options or the values won't be evaluated correctly.

0 0
replied on February 9

I'm sorry Blake, but I do believe that is accurate.  The setFieldValues function dictates the selected option(s) for checkboxes or radio buttons, but it doesn't change the text that is displayed with the options.

What we would need is for the changeFieldSettings function to be able to change the text that is included with the options, but not the values that are behind them.  But looking at the Help text for the LFForm interface, it doesn't list them as something that is currently available with the changeFieldSettings function.  I've also played around with it a lot trying to make it work, and couldn't get it working either.

If you or someone else has some example code showing how to change the text on the options of checkboxes and radio buttons, I would be extremely interested in seeing it.  But until that happens, I'm going to adamantly say that it isn't currently possible.

0 0
replied on February 9

@Matthew Tingey@Blake Smith, Thank you both for your time on this matter. The goal is to change the labels on the choices (options) in the radio button when there is an event, but not the values,  so the workflows will not be impacted. As @Matthew Tingey said, "If anyone has some example code to get this" in Laserfiche Cloud, it would be kind if you could share it with us. If not, as @Matthew Tingey, and @Blake Smith, I'm also afraid that this feature is not available on Laserfiche Cloud yet. Do you know, how to share this question with the Laserfiche Team to get an official answer from Them?

0 0
replied on February 9

As I mentioned previously, it is not available for Laserfiche Cloud. @████████it appears that the documentation was not updated for the function that this is done with. You are correct though; it was not with the setFieldValues it is the changeFieldOptions. Laserfiche is working on getting the documentation updated.

 

1 0
replied on February 9

Oh.  Okay.

Bummer for Cloud.  sad

I sure hope you are right - I'm excited to see that documentation updated and how to do that functionality, because I really tried to do it without any success.

0 0
replied on February 13

@████████ it looks like the documentation has been updated: Javascript in the Forms Designer (laserfiche.com)

 

0 0
replied on February 13 Show version history

Oh nice - so the function is LFForm.changeFieldOptions

I just tried it, and was able to change the option labels in checkboxes, radio buttons, and dropdowns!

When I used the "replace" mode to change the label but keep the same value each time, it retained what I had selected even though the labels changed after I had selected them.  This is great!

I'm happy to be proven wrong about this function not existing.  smiley

@████████- I don't know whether it will work in Cloud or not - but you could give the LFForm.changeFieldOptions function a try to see if that works in your environment.

0 0
replied on February 13

It is not available in Cloud.

0 0
replied on February 13

If it helps - here is an example process that I put together when I was testing out these functions.  You just have to change the file extension from TXT to XML to be able to import it into LFForms.

0 0
replied on February 13

That's a bummer about not being available in Cloud.

0 0
replied on February 13

@Blake Smith, thank you for the update.

@Matthew Tingery, I have already tested on Cloud, But It doesn't work.

 LFForm.changeFieldOptions( { fieldId: 25 }, [{label: "NewLabel", value: "1"}], "replace"} );

Anyway, if it's already working on premise, it's just a matter of time for it to work in Laserfiche Cloud, I hope.

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

Sign in to reply to this post.