1. Fabrik 3.9 has been released. If you have updated Joomla to 3.9, this is a required update.
    Dismiss Notice
  2. If you update to Joomla 3.9.16, you will have to update Fabrik from the latest GitHub version, to fix a bug introduced in Joomla, which makes it impossible to list front end folder locations in backend JForms. This affects things like template selection.
    Dismiss Notice

JS how to get value from...

Discussion in 'Standard Support' started by dejant, Oct 13, 2015.

  1. dejant

    dejant New Member

    Level: Community
    Hello,

    Im using JS List Plugin to grab some data and send it to form element. Wiki help just dosen't says much.

    Like to know how to get value (table cell data) from JS Object.

    Code (Javascript):
     console.log(rows)
    Firebug returns: Object { 4={...}}

    If I look DOM I can see all I need... but dont have a clue how to grab data.

    Thx for help.
     
  2. cheesegrits

    cheesegrits Support Gopher Staff Member

    Level: Community
    The wiki page seems to tell you pretty much everything you need to know. The rows object contains the data for the selected rows, indexed by the rowid. The selected indexes (rowids) are in the ids[] array So for example on my test table, if I select row 7, and want the userid element ... that's ...

    Code (Text):
    var selected_userid = rows[7].fab_junk___userid_raw;
    But obviously you have no a-priori knowledge of which row(s) will be selected, so as the wiki says, you need to "iterate through the data object, or otherwise do with it what you need to, using standard JS". There's lots of ways to iterate an object in JS, the easiest here is probably to take advantage of the Mootools framework, and turn the rows object into a Moo extended hash which you can then do each() on ...

    Code (Text):
    $H(rows).each(function (row) {
       var this_userid = row.fab_junk___userid_raw;
       var rowid = row.__pk_val;
       // do stuff with rowid and userid here ...
    });
    Note the use of __pk_val, which is the rowid of the selected row you are processing.

    Or you can use the 'ids' array, which is an array of the selected rowids, with which you can index the 'rows' object. So if you only care about the first selected row, and want to grab (say) the userid to pass to a form URL on the query string, the rowid for that will be in ids[0] ....

    Code (Text):

    var this_userid = rows[ids[0]].fab_junk___userid_raw;
    var url = "index.php?option=com_fabrik&view=form&formid=123&yourtable___userid=" + this_userid;
     
    As I don't know exactly what you are trying to do, I can't really give you any more specific advice. If you need more help, give me a more detailed explanation of what you are trying to do.

    -- hugh
     
  3. dejant

    dejant New Member

    Level: Community
    This is what I need...Thanks a lot.

    Task is to grab selected rows data from popup list and populate form text field.
    If it's useful for anyone...

    Code (Javascript):

    var listdata = Fabrik.getBlock('list_xx').options.data;
    var str = "";  
    $H(rows).each(function (row) {
        var celldata = row.list___element_name;
        str += celldata + "\n";
        document.getElement('#form_name___element_name').innerHTML = str;
    });
     
    And, of course in your form_xx.js
    Code (Javascript):

    function myWindow() {

    Fabrik.getWindow({
                     id : 'myWin',
                     contentType: 'html',
                     loadMethod: 'xhr',
                     contentURL :'index.php?com_fabrik&task=list.view&listid=XX&tmpl=component&resetfilters=0',
                     title : 'Select items',
                     width: 550,
                     height: 600,
                     'minimizable': false,
                     'collapsible': false,
                     onContentLoaded: function () {
                     console.log('complete');}
                     });
    };
    function myWindow() is trigged by button in a form.
     
    Last edited: Oct 19, 2015
  4. cheesegrits

    cheesegrits Support Gopher Staff Member

    Level: Community
    Another useful element object method is update(), which as well as setting the form element's value (which is often not as simple as just poking it into an input) will also take care of firing any events (like join elements needing to fire CDD updates, or calc elements firing their AJAX re-calculations), and any other housekeeping needed by the element type.

    -- hugh
     

Share This Page