list with php-plugin and js code too early

Status
Not open for further replies.

susannanam

Member
hi all,

i have a list with a php plugin. in that plugin i change the content of a table. that works fine so far.
as it says the JS code will be executed AFTER the php part, i then open a window, based on the changed table.

the window opens but it takes the "previous" content of the table. as i said, the content is changed if i check the table. i then just click twice on the button of the php plugin and then it shows correct. how can i make that js code wait and only take the updated content of the table?

thanks for any help
susanna
 
Well, the code actually runs before the PHP part. The tooltip is perhaps a little confusing, but what it says is:

Any JS code code entered here will be evaluated at the end of this plugin buttonAction() method. If your code returns false, the submit will be aborted. The selected rows data is accessible in the array 'rows'

Meaning that it runs prior to the submission of the plugin to the server, and is designed to allow you to abort submission or modify data going to the server, rather than process results. The key there is "If your code returns false, the submit will be aborted", which does clearly imply that it runs before the plugin is submitted to the server, otherwise it wouldn't be able to abort the plugin submission.

Are you using AJAX handling for your lists? If so, you should be able to run your JS by listening for the fabrik.list.submit.ajax.complete event, which is fired by the main list JS once it has finished processing the response form a list plugin. In a ./components/com_fabrik/list_X.js file (replace X with your numeric list ID), do something like this:

Code:
requirejs(['fab/fabrik'], function () {
   Fabrik.addEvent('fabrik.list.submit.ajax.complete', function (list, json) {
      // your code here
   )};
}

The 'list' arg will be the main list object, 'json' will be an array (I think, might be an object) with the updated list data. Although at this point, the updated data will have been applied to your list, so you should just be able to re-use your existing code.

-- hugh
 
thanks Hugh, yes i definitely misunderstood. i have now tried your advice but it does not yet open the window. i copied it in ./components/com_fabrik and also in ./components/com_fabrik/js but neither works. this is how my list_148.js file looks like:

Code:
requirejs(['fab/fabrik'], function () {
  Fabrik.addEvent('fabrik.list.submit.ajax.complete', function (list, json) {
      window.open('http://www.nets-box.edu.na/index.php?option=com_fabrik&view=list&listid=149&tmpl=component','Statement','width=1200,height=600');
  )};
}

do you have any idea what is wrong please?
susanne
 
ok for now i made a workaround... two php plugins ;) one creates... the other one shows... so two clicks instead of one but i think that is not the end of the world ;)
 
Status
Not open for further replies.
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top