1. We suggest you do NOT update to Joomla 3.8.10 until we can resolve an issue it causes with caching in Fabrik. If you do install it, you'll need to disable Joomla's "System Cache" in the global System settings.
  2. Apologies for the recent server outage, a planned migration by our host provider to a new location turned into a bit of a nightmare.

executing element javascript on a repeating group

Discussion in 'Professional Support' started by skyrun, Jun 28, 2018.

  1. skyrun

    skyrun Active Member

    Level: Professional
    on this repeating group form:
    upload_2018-6-28_12-28-18.png
    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).
     
  2. skyrun

    skyrun Active Member

    Level: Professional
    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.

    Code (Javascript):
    var rownum = this.options.repeatCounter;
    var id = $('srms_work_order_labor___who_'+rownum).value;
     
  3. cheesegrits

    cheesegrits Support Gopher Staff Member

    Level: Professional
    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.

    Code (Text):

    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
     
  4. cheesegrits

    cheesegrits Support Gopher Staff Member

    Level: Professional
    PS ... you're lowballing my hourly rate by a lot, there. ;)

    -- hugh
     

Share This Page