executing element javascript on a repeating group


Active Member
on this repeating group form:
View attachment 17277
i have element javascript on 'who' that fires onChange. it looks up the hourly rate for the person selected (using index.php?option=com_fabrik&format=raw&task=plugin.userAjax&method=hourlyRateLookup&id=xxx which functions to return {"rate":40} for example.

my question is how do i write the javascript to fill in the id of the person selected for that row....
if this were on a normal form (not in a repeat group) , i would use:
var id = $('srms_work_order_labor___who_raw').value;
to get the value and set somethinglike $('srms_work_order_labor___cost').value = jsonResponse.rate;

but that doesn't work when i'm in a repeat group.

where would i find the id of the user that was changed (and the row number to be able to set the corresponding cost column).
i think i may have figured it out.
i think this.options.repeatCounter gives the current row number.
so this will figure out the id that was changed. and i can set the appropriate cost_'+rownum also.
works on added rows too.

var rownum = this.options.repeatCounter;
var id = $('srms_work_order_labor___who_'+rownum).value;
Couple of things ...

It's better to use the Fabrik element object update() and getValue() methods, rather than getting and setting the value attribute directly on the DOM object. There's a lot of elements that do "other stuff" when you get or set their values, or don't have a single 'value' to set / get.

And the best way to get the repeat num is with the getRepeatNum() method.

var id = this.form.formElements.get('srms_work_order_labor___who_' + this.getRepeatNum()).getValue();

Note that in this case, I'm using the reference to the form's block in the element object (this.form). You can also get that with the Fabrik.getBlock('form_X') method.

And ... if you are meaning to use jQuery, don't use $(), use jQuery().

-- hugh