JS how to get value from...

dejant

New Member
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.

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.
 
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:
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:
$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:
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
 
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...

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
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:
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
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top