Hi,

I'm using php to print a view and after a submit on comment the view (only list comments) doesn't get refreshed.
$view = views_get_view('myview');
print $view->execute_display('block-1', array($node->nid));

the ajax views refresh settings page are ok.

Any help?

thanks

Comments

carvalhar’s picture

If i print_r($form) i can see that the form has the views_refresh array itens:

[#ajax] => Array
(
[enabled] => 1
[disable_redirect] => 1
[remove_form] =>
[scroller] =>
[views_refresh] => 1
[views_refresh_enabled] => Array
(
[comentarios] => comentarios
[comentarios:block_1] => comentarios:block_1
)

)

so far i couldn't tell what's avoind the view refresh.

any help?

carvalhar’s picture

i resolved this manually, but with this module i couldn't.
more info here:
http://drupal.org/node/1246672

twistedindustries’s picture

I am having the same issue and looked through the topic posted above but didn't really see any obvious fix. Any chance you could post what you did to fix it? I am seeing that all the views that it detects on the page are added to Drupal.settings. Does anyone know where that is done in this module and maybe we can look at modifying that? It seems as though it doesn't detect the page it is on as a view.

carvalhar’s picture

sorry, i did my own ajax call...
See http://drupal.org/node/1246672#comment-4856824 then i added :
$('#mycontainer).html(data.display);
Drupal.attachBehaviors($('#mycontainer'));

jthomasbailey’s picture

Carvalhar, would you mind pasting the exact code you used in template.php and the views embed code you used in node.tpl.php? I'm having a hard time understanding what you did.

carvalhar’s picture

ok, i'm pasting here, as a reference. From august (when i posted it here) to today, many things changed.

You'll need to create a JS plugin, adding a custom.js to your theme:

$(document).ready(function(){
	//see reference
	//http://drupal.org/node/463258
	//Available Hooks: init, submit, redirect, message, afterMessage, scrollFind, complete
	Drupal.Ajax.plugins.RemoveLoader = function(hook,args) {
		//alert(hook);
		//args cames from the form
		//it's useful to use the plugin jQuery Dump
        if(hook === 'submit') {
			//a comment was submitted
			$("#comment-form").append('<p class="ajax-loading">&nbsp;</p>');
			//$('#edit-submit').attr('disabled', 'disabled');
        }
		if(hook === 'redirect') {
               //do whatever you want after form has been submitted
			   $("#comment-form").find('p.ajax-loading').hide();
			   // get the ajax page by firebug console, contruct it by json and send it in your tpl
			   $.ajax({
				  type: 'get',
				  url: $("#AjaxURL").val(), 
				  success: function(data){
						$('#block-views-comentarios-block_1').find('div.content').html(data.display);
						Drupal.attachBehaviors($('#block-views-comentarios-block_1').find('div.content'));
						//$('#block-views-comentarios-block_1').find('ul.pager > li > a').
						//see / ajax.jsDrupal.behaviors.ViewsAjaxLinks					
						
				  },
				  dataType: 'json', //define the type of data that is going to get back from the server
				  data: 'js=1' //Pass a key/value pair
				});
				return false;		 
        }
        if(hook === 'afterMessage') {
				//if a error occurs
               //do whatever you want after message is displayed,
				$("#comment-form").find('p.ajax-loading').hide();
        }
	};
});

My tpl has an input hidden with the ajax full url, i'm using i18n:

($language->prefix == "en") ? $langView = $base_path . 'en/': $langView = $base_path ;
$urlhidden = $langView.'views/ajax?js=1&page=0&view_name=my_view_name&view_display_id=block_1&view_args='.$my_arg.'&view_path='.$_GET['q'].'&view_base_path=null&view_dom_id=4&pager_element=0';
 echo '<input id="AjaxURL" type="hidden" value="'.$urlhidden.'" />';
print $comment_region; // i added the views block to a region on my theme

But at the beginning i was using a preprocess function to add the view to my tpl, in template.php

function phptemplate_preprocess_page(&$vars) { 	
 $myview = views_get_view('my_view');
 $myview->set_arguments(array($myarg));
 $myview->override_path = 'current_path';
 $vars['comment_region'] = $myview->preview();
}
jthomasbailey’s picture

Hey thanks a lot, you saved me and probably a lot of other people some serious hair pulling.