How to get list row id to build url in js?

Status
Not open for further replies.

redant

Member
Hi Guys

Following guidance in the forum, I have come up with the following code attached to a custom js button in a list:
var url = 'index.php?option=com_fabrik&view=details&formid=14';
url = url + '&rowid=' + $('fab_requestor_job_details___id');
window.location = url;

The returned url does not include the row id:
... option=com_fabrik&view=details&formid=14&rowid=null

url = url + '&rowid=' + $('fab_requestor_job_details___id_raw');
and
url = url + '&rowid=' + $('this.rowid');

yields the same result

Please can someone show me my error - js is not my strong point.

Thanks!
 
Doing ...

Code:
 $('fab_requestor_job_details___id')

... won't get the the value of an element, it'll just get the jQuery object for that DOM object. Also, don't use $, use jQuery(), otherwise you'll probably end up with the Mootools object.

We'd need to know more about how exactly you are doing this. Is it in a list_X.js file? The button element has no list JS.

-- hugh
 
Thanks, Hugh

To explain:
In a list I am using the js plugin so that I can have a custom button - this all works fine.

In the JavaScript Code code window, when I use the following code:
var url = form_123.formElements.get('yourtable___some_element').getValue();
window.open(url);

as per Troester's link above, the button is completely unresponsive when clicked. The js never fires. I then came across the link I referenced above and that fires but does not return the row id element.

To answer your query; no, I'm not using a list_X.js file - this is directly into the js plugin field.

Even using the details view button from the built in function would work if I could find a way to change the button image but using an alternative image there results in a blank button...

Thanks to both you and Troester for the response.
 
I've had a chance to get back to this and tried your solution. (Please bear in mind that I'm pretty clueless when it comes to any form of java.)

So I tried:
var url = 'index.php?option=com_fabrik&view=details&formid=14';
url = url + '&rowid=' + jQuery('fab_requestor_job_details___id');
window.location = url;

Which returns: ... &formid=14&rowid=[object Object]

So - a step in the right direction. Now - off to w3schools to find out what thats about :)
 
I told you that in my previous post, doing $('whatever') won't get you a value,it'll get you a jQuery object.

And in this case, using the list JS plugin, that #fab_requestor_job_details___id doesn't exist. That only exists on forms. In a list, as there are multiple rows with the element in them, we use a class to identify them. But selecting that doesn't help, as you don't know which one the button was clicked on.

Which brings us to the next problem, which is that being a list button, it's expecting to be multi-selectable.

if you assume that they didn't select checkboxes and hit the "all" button, but clicked on one button, then the rowid for that will be in ids[0]. If you need something other than the rowid, rows[id[0]].yourtable___yourelement.

-- hugh
 
Thanks, Hugh

As I said - js and me - not mates. Last touched it in about '99

Found this post which clarified things for me: http://fabrikar.com/forums/index.php?threads/accessing-form-data-in-javascript.35789/ and along with your explanation above, the picture just came into focus.

Ok - I think I'm approaching this from the wrong end of the stick.

I'm going to go and have a rethink about my method here and possibly hack something together in PHP where I'm more comfortable.

Thanks for your time and teaching. Always appreciated.
 
Exactly what the details view button in a list does. It displays the form details corresponding to the row clicked.

My requirement is that I need a custom .png button to replace the bootstrap icon image which is the standard. I just couldn't find another way to do this other than with the button plugin in the list, which requires js for manipulation.

Another way I tried was to create a button element but irrespective of the path I place the image in, following guidance on this forum as well as the plugin documentation, I cannot get the image to display which is again why I defaulted to the plugin.
 
Did you try using the "Detail icon", under the Links tab in the list settings?

That can be a bootstrap icon name, or am icon file in one of the standard icon folders detailed in the wiki.

-- hugh
 
Hi Hugh

Yes, that was my very first stab at this but whether I use the
..\media\com_fabrik\images\x.png path
or the
..\images\x.png path,

the button remains blank - i.e. the button outline is there without an image on it.

Looking at Firebug output I see that button is rendered as an icon class (<i class="icon-detail " data-isicon="true"></i>) and therein lies the issue methinks which is why I was looking at an alternative way of doing the same thing.

I guess I could use some custom css ...
 
Last edited:
Hmmm, OK, looks like a change I made a while back when I moved the view icon handling into a layout is now forcing it to always treat that as an icon.

What you can do is override that layout, either globally or for a specific list template, by copying ...

./components/com_fabrik/layouts/listactions/fabrik-view-button.php

... to either of ...

./templates/<your site template>/layouts/com_fabrik/listactions
./com_fabrik/views/list/tmpl/<your list template>/layouts/listactions

You may have to create the subfolders if they don't exist.

Then in that file, change this line ...

Code:
<?php echo FabrikHelperHTML::image($d->list_detail_link_icon, 'list', '', array('alt' => $d->viewLabel));?><?php echo $d->viewText; ?></a>

... to ...

Code:
<php
$opts = array();
if (strstr($d->list_detail_link_icon, '.')) {
   $opts['forceImage'] = true;
}
echo FabrikHelperHTML::image($d->list_detail_link_icon, 'list', '', array('alt' => $d->viewLabel), false, $opts);?><?php echo $d->viewText;?></a>

That should force the image() helper to look for an image file if the name has a . in it, rather than using it as an icon class.

I'll look at adding that to that layout, test it here for a while and make sure it doesn't mess anything else up.

-- hugh
 
Thanks, Hugh

works perfectly.

Appreciated. I'll post back if I find any funnies caused by this but for now I'll close the post as solved.

Ant
 
Status
Not open for further replies.
We are in need of some funding.
More details.

Thank you.

Members online

No members online now.
Back
Top