rackem
Well-Known Member
I have a database join element, rendered as an auto-complete in a repeating group. I am trying to figure out the JS to copy the selection from the previous group when a user adds a group.
The following code performs this operation already for two dropdown elements. The last section (noted with comment) is where I am struggling.
It is confusing because the getElements statement gets 2 elements per group for the autocomplete instead of just one like the dropdown elements. The 1st element contains the autocomplete's label and the 2nd contains its value.
The above code gets the previous group's element value and assigns it to the next group's element. However the autocomplete field remains empty.
I tried getting and updating the label but received the error "cannot call method 'update' of null". I also tried using "setValue" instead of "update" with basically the same result.
Is there another way to set an autocomplete using JS?
The following code performs this operation already for two dropdown elements. The last section (noted with comment) is where I am struggling.
Code:
Fabrik.addEvent('fabrik.form.group.duplicate.end', function(form, event, g_id, r_count){
var tables = $('group' + g_id).getElements('select[name *= mps_bouts___table]');
tables[r_count].selectedIndex = tables[r_count - 1].selectedIndex;
var games = $('group' + g_id).getElements('select[name *= mps_bouts___game]');
games[r_count].selectedIndex = games[r_count - 1].selectedIndex;
// These last lines are the ones in question
var opponents = $('group' + g_id).getElements('input[name *= mps_bouts___opponent]');
var last = opponents[2 * r_count - 1].getValue();
var new_id = opponents[2 * r_count + 1].id;
form.formElements.get(new_id).update(last);
});
It is confusing because the getElements statement gets 2 elements per group for the autocomplete instead of just one like the dropdown elements. The 1st element contains the autocomplete's label and the 2nd contains its value.
The above code gets the previous group's element value and assigns it to the next group's element. However the autocomplete field remains empty.
I tried getting and updating the label but received the error "cannot call method 'update' of null". I also tried using "setValue" instead of "update" with basically the same result.
Is there another way to set an autocomplete using JS?