The Problem
A user asked the following question on the FormidableForms Community Forum:
I have a form in which I used the following script to copy text from one text field to another (lookup text field). It worked until now. But now that I have moved these two fields into a repeatable section, the script has stopped working.
The Solution
When you added the fields to the repeatable section, the field ID changed.
The first field on form is field_o8v4sw-0. When you add a row to a repeatable section, the field ids will incremented. So, if you 9 more rows, the field ids will be:
field_o8v4sw-0
field_o8v4sw-1
field_o8v4sw-2
field_o8v4sw-3
field_o8v4sw-4
field_o8v4sw-5
field_o8v4sw-6
field_o8v4sw-7
field_o8v4sw-8
field_o8v4sw-9
Counting always starts at 0. Instead of checking for each individual field to change, this can be done with a wild card.
var sourceField = $(this).val(); //source field key
In order to determine the destination field, you're going to have to do some string manipulation. So the first thing we have to do is get the actual ID of the target field.
Next, we need to get the number at the end of the ID. This number will be the same as the destination field.
Now we can populate the destination field.
$(destination_field).val(sourceField);
Here is your new jQuery:
Thank you for this enlightening post. I found out though that jQuery wasn’t able to trigger changes for indexes greater or equal to 1.
The solution I found (after reading https://stackoverflow.com/questions/7244935/how-to-apply-jquery-change-for-input-elements-that-have-id-starting-with-a-pa) :
$(“[id^=field_o8v4sw-]”).live(“change”, function() {