• Hello Fabrik Community

    Fabrik is now in the hands of the development team that brought you Fabrik for Joomla 4. We have recently transitioned the Fabrik site over to a new server and are busy trying to clean it up. We have upgraded the site to Joomla 4 and are running the latest version of Fabrik 4. We have also upgraded the Xenforo forum software to the latest version. Many of the widgets you might have been used to on the forum are no longer operational, many abandoned by the developers. We hope to bring back some of the important ones as we have time.

    Exciting times to be sure.

    The Fabrik 4.0 Official release is now available. In addition, the Fabrik codebase is now available in a public repository. See the notices about these in the announcements section

    We wish to shout out a very big Thank You to all of you who have made donations. They have really helped. But we can always use more...wink..wink..

    Also a big Thank You to those of you who have been assisting others in the forum. This takes a very big burden off of us as we work on bugs, the website and the future of Fabrik.

PHP list plugin javascript stopped working

Bauer

Well-Known Member
I was using some javascript in a php list plugin to prevent the code from running in a certain situation.
Suddenly (not sure when, but it worked last time I tried a few weeks ago) the code errors out.

Per the Wiki, I expected to use (was using) the variables rows and ids.
But now both 'ids' and 'rows' are giving errors and show as undefined or empty when sent to the javascript console.log.

Please tell me this is not "just me" - and then please fix it so the javascript in a php list plugin will work as expected again.
 
Works fine for me.

We don't define an ids, only rows (an object of row objects). If you need the selected ids, you have to get that yourself (see the php.js for how we do this). Maybe you are thinking of the js list plugin, where we provide both ids and rows? Here's the code for php.js, which hasn't been changed in a long time:

https://github.com/Fabrik/fabrik/blob/master/plugins/fabrik_list/php/php.js

As you can see, no 'ids' var, just rows.

-- hugh
 
The Wiki for the Javascript List Plugin has these 2 examples...
JavaScript:
console.log(ids); //outputs an array of the selected row ids
console.log(rows); // outputs a object key'ed on the selected row ids, each value is an object containing the row data.
So I assumed (and tested/tried using) both.
ids throws an error and rows is an empty array.

Anyhow, here is the code I was using...
JavaScript:
var applied_val = rows[0]['fb_breakouts___applied_raw'];
var applied = (applied_val=='1') ? true : false ;
if (applied === false){
  alert("Report cannot be generated until it has been 'Applied'.");
}
return applied;

It doesn't work anymore. The console has error...
Uncaught TypeError: Cannot read property 'fb_breakouts___applied_raw' of undefined

Figures it was a "just me". Phil's law strikes again.:mad:
 
Works fine for me.

We don't define an ids, only rows (an object of row objects). If you need the selected ids, you have to get that yourself (see the php.js for how we do this). Maybe you are thinking of the js list plugin, where we provide both ids and rows? Here's the code for php.js, which hasn't been changed in a long time:

https://github.com/Fabrik/fabrik/blob/master/plugins/fabrik_list/php/php.js

As you can see, no 'ids' var, just rows.

-- hugh
I was trying to think of what I might have changed to break this.
I add a 'group by' to the list a few days ago.
That's what breaks it.
If I disable the groupby - it works fine again.
But I want to be able to use groupby on this list too!:mad:
 
The Wiki for the Javascript List Plugin has these 2 examples...

Right. But that's the Javascript List Plugin. According to the thread subject, this thread is about the PHP List Plugin. Which isn't the same. One could argue that it should be, but it isn't. It just has 'rows' which are not indexed by row id.

-- hugh
 
I was trying to think of what I might have changed to break this.
I add a 'group by' to the list a few days ago.
That's what breaks it.
If I disable the groupby - it works fine again.
But I want to be able to use groupby on this list too!:mad:

I shall take a look.

-- hugh
 
OK, I've modifed the php plugin JS to do the same thing as the js plugin, and create the ids array, and the rows object is now keyed by rowid. And it fixes the group by issue.

It's possible this may break backward compat for existing PHP plugin code that operates on the sequentially keyed rows object, although most code I can picture in my head wouldn't break, but moving forward it just makes more sense for both plugins to do it the same way.

https://github.com/Fabrik/fabrik/commit/54bdb83540c617ef17bc15e68614bc2a21cdcd44

-- hugh
 
You've been a busy guy - considering it's supposed to be a holiday.:p (But I'm in the same boat.)
Thanks a bunch for getting to this.

Now if you can implement the github pull request changes I made to the list copy plugin that allow you to specify what columns get reset to their default values during copy (or look at my code at github to get the basic idea of how I think it should work - and fix it with any modifications to that you might have) - then I'll be able to just use the list copy plugin rather than the php plugin code I wrote. (I haven't tested your fix for the groupby bug yet - but I'm sure you fixed it.)

Also, today I changed the Yes/No plugin to allow images for Yes/No - so in a list view you can have an image that better represents what the toggle does (in my case an image of a locked lock or an unlocked lock). My 'client' wanted something a little more professional looking than one-color icons. It's pretty basic - just 3 more variables (optionally) added to the $displayData array used in the layout file from those new configuration parameters - which will display the image instead; and set the width to resize if specified. Do you think other Fabrik users might be interested in that? If so I'll put it at Github in the morning.
 
I saw the pr, haven't had time to look at it. Sure, add the yesno stuff. If it looks useful I'll merge it.

Sent from my HTC6545LVW using Tapatalk
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top