Changes attribute values from a list. Must be used inside an ajaxable context (group, each). |
|
| see publish, zena 1.0 | |
The ‘swap’ method is used to loop through a list of values by repeatedly clicking on a link.
In this first example, the ajax call replaces the whole “each” block after ‘flag’ value changes.
When the ‘update’ argument is omitted, the closest block or each loop is used.
<ul do='tasks from project'> <li do='each' class='#{flag}'> <r:swap attr='flag' states='todo,done,alert'/><r:link/> </li> </ul>
In this second example, only the defined “block” is changed.
<ul do='tasks from project'> <li do='each'> <span do='block' class='#{flag}'> <r:swap attr='flag' states='todo,done,alert'/><r:flag/></span><r:link/> </li> </ul>
This example uses the integer field “custom_a” and the states includes the nil value.
<div id='swap' class='orange' do='block' green_if='custom_a == 100'> <span do='swap' states='100, ' attr='status' publish='true' do='t("img_status#{status}")'/> <r:title/> </div>
advanced
In case you want to change more then one argument or need other settings, you can use pure rubyless to achieve the same result with the “next_in_list” method and setting ‘update’ as link parameter:
<r:link action='update' update='_page' node[flag]='#{next_in_list(flag, "todo,done")}'/>