public
Description: JavaScript Application Framework - JS library only
Home | Edit | New

Tab_view

A tab view creates a tabbed view in the page.
Syntax:

<%= tab_view :name_of_tabsystem, :lazy_tabs => true | false, :segments =>[ array-of-tabs ] %>

where

  • :name_of_tabsystem :: name of tab system for future reference
  • :lazy_tabs :: Whether the tabs should be loaded when first clicked (true) or when the page loads (false)
  • :now_showing :: [optional] Which tab to show on load, should be the name of the tab without the tab suffix.
  • :segments :: An array of tabs. This array can have the following syntax:
    • [:the_first, :the_second] :: specifies two tabs and uses the names of the objects to label the buttons that will activate the tabs; in this example, the tabs will be labelled ‘The First’ and ‘The Second’.
    • [ [:the_first, ‘Look Here’], [:the_second, ‘Look There’] ] :: uses the provided names ‘Look Here’ and ‘Look There’ as the labels of the activation buttons. To add localisation, replace ‘Look Here’ by ‘loc(%(localisation_string))’.

For every tab (i.e., view) specified in the :segments array, contents must be provided by creating a .rhtml file of the same name as the tab (in this example, “the_first.rhtml” and “the_second.rhtml”). Start the .rhtml file with the override:

<% view :the_first_tab do %>

and end the file with

<% end %>

Note that the view-identifier should be the symbol in the :segments array with the suffix “_tab”.

If you want to set the tab that is selected on load, use the :now_showing => ‘name_of_tab’. So, for instance in the above example one can have the second tab selected on load with the following code:

<%= tab_view :name_of_tabsystem, :lazy_tabs => true | false, :now_showing => ‘the_second’ , :segments => [ [:the_first, ‘Look Here’], [:the_second, ‘Look There’] ] %>
  • If you look in the docs you will notice that it says nowShowing and not now_showing. nowShowing is the name of the Javascript property used to set the currently selected tab programatically. :now_showing is a Ruby symbol which is converted to camelCase when the helper generates the Javascript.

Comments

The conversion to camelCase also applies when names with underscores are used as tab symbols. The now_showing property of the nested tab system should point to a camelCased name of this tab:

<%= tab_view :name_of_tabsystem, :lazy_tabs => true | false, :now_showing => “firstTab”, :segments => [ :first_tab, :second_tab ] %>

so firstTab instead of first_tab! -Maurits

Please confirm that the statement about naming the view-identifier is correct! Thanks! -bruml2

Bruml2: it is; I used your example and it seems to work. — gdey

Added the bit about :now_showing. Minor edits. — gdey

Minor edits. —bruml2

Last edited by mauritslamers, Fri Jul 04 15:48:31 -0700 2008
Home | Edit | New
Versions: