Views Flag Refresh
Overview
Views Flag Refresh allows site administrators to configure which views are refreshed automatically via AJAX when certain flags are selected. This is useful when you have a view that filters by flagged content and you want the view to be refreshed automatically when content is flagged or unflagged elsewhere on the page.
Configuring the module
- Create a view
- Add your fields including the Flag link field
- In the OTHER section set "Use AJAX" option to Yes
- Also in the OTHER section click the link next to "Flag refresh"
- Select the current view
- Click Apply
- Clear cache
- Now your view should refresh when you click on a flag link

Developer Documentation
The Views Flag Refresh module provides an API for developers to create custom widgets that alter the view’s display during refresh. One example is the "Throbber image" widget that comes bundled with the core module. While the view is refreshing, an animated GIF image is displayed in place of the content letting the user know a refresh action is being taken.
The API consists of a Drupal hook implementation that defines the widget and some javascript code that alters the content. In this documentation, we will create a simple widget that displays the text "Refreshing..." while the action is being taken. The example uses the fictitious "mymodule" module that contains the files "mymodule.module" and "mymodule.js". For more information on creating modules, refer to the Module developer’s guide.
PHP API
The first step in creating a widget is implementing hook_views_flag_refresh_widgets(). The code below defines our "text" widget by specifying the the javascript file and instance method that will alter the display. When a view configured to use our widget is rendered, the javascript file will automatically be added to the page via drupal_add_js(). Refer to the API example file for more detailed information on the hook’s anatomy along with additional keys that are available.
// $Id$
/**
* @file
* mymodule.module
*/
/**
* Implementation of hook_views_flag_refresh_widgets().
*/
function mymodule_views_flag_refresh_widgets() {
$widgets = array();
$widgets['test'] = array(
'title' => t('Textual message'),
'theme hook' => 'text',
'js file' => drupal_get_path('module', 'mymodule') .'/mymodule.js',
);
return $widgets;
}
JavaScript API
The Views Flag Refresh module provides a lightweight theme system for javascript. In the code above, the "theme hook" is an instance method of the FlagViewsRefresh.theme class that is expected to be implemented in the javascript file. The "theme hook" method is called after the flag action has completed and before the the Views AJAX request is made. The method has access to following two class properties:
- this.target: A jQuery object containing the content being refresh.
- this.settings: Some of the widget settings defined in hook_views_flag_refresh_widgets().
In the code below, the method simply replaces the content of the view with our text.
// $Id$
/**
* Theme hook that adds the text in place of the view content.
*/
viewsFlagRefresh.theme.prototype.text = function() {
$(this.target).text(Drupal.t('Refreshing...'));
}
Help improve this page
You can:
- Log in, click Edit, and edit this page
- Log in, click Discuss, update the Page status value, and suggest an improvement
- Log in and create a Documentation issue with your suggestion