Display Single selection from dynamic dropdown

By: Jan Siwinski | Asked: 08/29/2024
ForumsCategory: How-toDisplay Single selection from dynamic dropdown
Jan Siwinski asked 4 months ago
I'm Trying to dynamically populate the name label of repeating fields with selections from a dynamic dropdown a page previou in a multipage form.

I originally achieved this on a previous build of the site with the help of the linked javascript code. but for the life of me I can't seem to get it to work anymore plus my skills are rudimentary so I had to repeat the code each time rather than knowing how to loop through it.

What I had hoped to do is use a view within the repeating fields name label that shows All Entries, with a limit of one  "1", "Ascending". Then use a parameter in the views shortcode to display the first selection of the dropdown field.
In the second repeater I would use a parameter to show the second selection, and so on. But no matter what I do I only ever get the drop downs whole array printed, rather than showing the first in array, or second in array.

Is my goal possible using a view/or views with filtering?
2 Answers
Best Answer
Jan Siwinski answered 4 months ago

I managed to figure it out with JS. Just a minor change really. I did go back down the shortcode route as 
Victor suggested but I still couldn't get it to work as I liked.I'll leave the answer here in case anyone has the same need as me in the future.So in short, I wanted to take answers from a dynamic dropdown checkbox and use those answers one at a time to fill the field name of each repeating field on the following page of a multi page form.To get the answers of the dynamic dropdown field I set the form to save drafts and used the JS and  shortcode:

var names = '[frm-field-value field_id=138 user_id=current]';     
var nameArr = names.split(',');     
console.log(nameArr);   
document.getElementById("repeaterOne").innerHTML = (nameArr[0] + "<br>"); document.getElementById("repeaterTwo").innerHTML = (nameArr[1] + "<br>");
 

Then I went to the customise html part of the form and gave each repeating fields <h3> tags an ID. EG ID="repeaterOne"In the after fields of the customise HTML section I used the following JS: The shortcode printed an array of "apples, bananas, pears" for example.
The JS split the array by comma and wrote it to the console. Thehe second chunk of JS found the <h3> elements by ID and injected the correct variable into it. With nameArr[0] being the first slice of the array, nameArr[1] being the second etc.

Victor Font answered 4 months ago
I'm totally at sea to understand your question. You say you want to "use a view within the repeating fields name label". Are you saying you want to place a repeater field label with a Formidable view? I don't know if you're looking for a solution about nested views or something else. Would you please elaborate and describe your requirements with more detail?
Jan Siwinski replied 4 months ago

I have a multi page form. On page 1 is a dynamic field. On page two are repeater Fields.

I would like to dynamically populate the name of each repeater field with each of the selections from the dynamic field on the previous page. (Dynamic checkboxes)

Using a few methods I’ve managed to print the whole dynamic fields array into the name field of a repeater on page two, but not 1st in array for repeater one or second in array for repeater two.

I’m currently trying to achieve this using a view. The short code of which I’m placing in the name field of each repeater.
For repeater one I’m placing param=“1” within the views shortcode. In the repeaters name field. For repeater two I’m placing param=“2” within the view short code in the repeater 2’s name field.

In the view I’m using the print splice part of the code linked above within [get param=“1”] document.write(nameArr[0] + "");[get param]

When I do get it to show the single selection it breaks the rest of the form but with no error in the console. Is there a better way to do this. ?

Hope that explains it more clearly

Victor Font replied 4 months ago

You do realize that dynamic fields only display text values but the actual value is the entry id of the lookup record. I'm still not entirely clear why you're passing an entry id as the parameter. I may be missing something, but it sounds to me like you may be wanting to create a default value for the repeater rows, or do you really mean the field label and not the field's default value?

There are different ways to do this. You may be able to create you're own shortcode and simply apply it to the custom HTML for the repeater.

Jan Siwinski replied 4 months ago

If the default value can be dynamic, then yes. I have tried that route but again it only showed an array. Rather than the first in array or second.

So in short if the user select apple, banana and grapefruit from the dynamic dropdown(checkbox), id like repeater one to have the name Apple, repeater two to have the name banana and repeater three to have the name grapefruit. But ithey would need to be able to dynamically change if the user changes their selection in the dynamic dropdown

Jan Siwinski replied 4 months ago

Yes the actual name field of the field. It’s more for visual representation

Victor Font replied 4 months ago

Then I would look at creating a custom shortcode to display the label as you desire with each additional row in the repeater. Navigate to your form's Customize HTML page.

You want to look at the fields that come after the repeater section header. For a text field, you'll see the HTML used to generate each row. Look for the label tag? Replace the [field_name] shortcode with your own shortcode that displays the content the way you want.

Victor Font replied 4 months ago

If not a shortcode, you can replace the [field_name] shortcode with plain old HTML that you can change dynamically with jQuery. There are multiple approaches.

Jan Siwinski replied 4 months ago

That was actually my original approach. My issue has more been splicing the js correctly to show the correct selection for each rather than an array. I’ll try again with the shortcode route rather than js.

Thanks Victor

Making the Best WordPress Plugin even better - Together

Take on bigger projects with confidence knowing you have access to an entire community of Formidable Experts and Professionals who have your back when the going gets tough. You got this!
Join the community
crossarrow-right