Hi!
I'm trying to build a dynamic repeater form (picture below) where user can select begin-hour from dropdown and end-hour from another dropdown. Begin-hour from next repeater row should be same than end-hour before.
Is it possible to:
- populate begin-fields based on end-field on previous row?
- add dynamic options to dropdowns based on another value in repeater area?
Any help available?
I've been trying to add connected dropdowns inside a repeater area in CF7, and seems that reloading a dropdown breaks the datamodel creating a key called #repeater.
What I'm trying to find as a solution:
- How to create a connected dropdowns in CF8?
- How to update dropdown value based on another field either in the same row or in the previous row?
- How to send value to custom php to create dropdown options inside a repeater area
Hi tuomas
I do not think you can do this without some custom javascript code!
Hi Max!
Thank you for your reply! I'm trying with connected dropdowns -style in CF7, but cannot find variables to get value from spesific repeater area. There also seems to be a bug that #repeater-number is replaced as a text when reloading a field in repeter area.
Is there a possibility to create connected dropdowns in CF8? I think it's a solution that I could use to get forward with my case.
I've had some progress with my usecase, and now the form and dropdown options are loaded correctly. The current form setup looks like this:
The form is loaded correctly and periods are shown as expected.
Problem is when I'm trying to save new values. My plan is to submit form every time any of the values is changed, and event trigger is working correctly when dropdown value changes. I've added a loop into submit form -section, but loop-variable includes only the last item of repeater, and it's not updated with new values user has selected. Form data includes only fields inside last loop item. I've tried to fix the problem by adding a loop-key into field name, but haven't found a solution to find the correct way.
Is there a way to create an array from loop items to send new data to submit form?
Hi tuomas
Are you using a Loop or a Repeater ? if the issue is naming your fields then your fields names should end with closed square brackets to submit an array of values:
period_start_hour[]
Thank you Max, getting forward:
What I would like to achieve is array like:
[save_settings] => Array
(
[0] => Array
(
[period_start_hour] => 11
[period_end_hour] => 22
)
[1] => Array
(
[period_start_hour] => 22
[period_end_hour] => 31
)
etc...
I can build this array with php from different field names, but is it possible to name fields inside loop including loop-key to get this kind on array straight from form? I've understood that in repeater area it's possible to use [n], but this loop area is needed to create dropdown values for eacth row. I’ve already tried to name fields with [{var:Loop.key}] but it doesn’t seem to work.
Thank you!
- Tuomas
in that case the fields names will need to be:
save_settings[][period_start_hour]
but if you need to set the number in the [] then you may use {var:loop_action_name.key}, where the "loop_action_name" is the name of the Loop action, in your case that is "load_periods"
Unfortunately shortcodes inside brackets do not work correctly. If I use field name as you posted it creates array as expected adding each element under different keys. But if I use
save_settings[{var:load_periods.key}][period_start_hour]
as field name the form doesn't submit at all.
So does that solves the issue ?
what is the generated field name when you use save_settings[{var:load_periods.key}][period_start_hour] ?
Actually field names are generated correctly, but events are not working after adding {var:load_periods.key} into dropdown fields name.
I have an event trigger "on Value Changes" and "Trigger submit_form" in both dropdowns, and event listener in another of them to listen event submit_form and action is Submit form.
Without a shortcode inside field name this trigger and listener are working correctly, and form submits every time when any dropdown-value is changed.
Great, so issue is now solved without the shortcode ?
Yes and no, I also need this event trigger to function correctly.
Meanwhile I can build array for save data -action with php from set of arrays based on field name "field_name[]".
It would be easier to handle submitted form data if I could use
"model[{var:loop.key}][field_name]"
as a field name, but with this kind of field names events stop working and form is not submitted when dropdown value is changed.
Seems that event triggers and event listeners are not functioning correctly if field name contains shortcodes. Otherwise form is functioning correctly and fields are named as expected with or without shortcodes.