Click here to see Swap Demo.
JSControlsTags Swap is able to manage several lists and swap items between there. This control is able to :
This control generate UL/LI for items comming from an HTML select options. It use Draggable control of scriptaculous, to manage drag/drop. To use Swap control, you must populate an HTML select and attach your select with Swap to generate UL/LI.
jscontrols:swap taglib manage swap on client side. Here JSP code of this example :
<!-- First List where Swap control generate UL/LI--> <div id="divId1" ></div> <!-- Second List where Swap control generate UL/LI --> <div id="divId1" ></div> <!-- HTML select which is used by Swap to populate list with UL/LI--> <select name="select1" id="select1" multiple="true" > <option value="item1_1" >Item 1 from first list.</option> ... </select> <select name="select2" id="select2" multiple="true" > <option value="item2_1" >Item 1 from second list.</option> ... </select> <!- Swap definition for the first list, which accept items from second list --> <jscontrols:swap source="divId1" items="select1" styleClassList="list1" selectAllListAction="selectAllList1" selectNoneListAction="selectNoneList1" > <jscontrols:accept source="divId2" swapAction="swapList2ToList1" /> </jscontrols:swap> <!- Swap definition for the sesond list, which accept items from first list --> <jscontrols:swap source="divId2" items="select2" styleClassList="list2" selectAllListAction="selectAllList2" selectNoneListAction="selectNoneList2" > <jscontrols:accept source="divId1" swapAction="swapList1ToList2" /> </jscontrols:swap>
jscontrols:swap define swap property for a list.
Parameter | Description | Required |
var | Name of the JavaScript object swap created. | no |
source | HTML Div HTML container with contains items (LI). | yes |
items | HTML select which is used by swap to populate the list with UL/LI | yes |
styleClassList | Style class for the list generated with UL/LI | yes |
selectAllListAction | HTML element (Id of HTML href, button ...) used to select all items of the list on click event. | no |
selectNoneListAction | HTML element (Id of HTML href, button ...) used to select none items of the list on click event. | no |
enabled | true if swap list must be enabled (stop Drag/Drop and selection of items) and false otherwise. By default swap list is enabled.. | no |
onEnable | Event launched when swap control is disabled/enabled. | no |
dragDropEnabled | true if drag/drop is enabled and false otherwise. By default drag/drop is enabled. | no |
onSwapComplete | Event launched when swap items is finished. | no |
To define items that list can accept, use jscontrols:accept for each list swap control must accept.
Parameter | Description | Required |
source | HTML Div HTML container with contains items (LI). | yes |
swapAction | HTML item (HTML href, button ...) used to swap items of the first list to second. | no |
Here an example of Swap defintion for a list (divId1) which must accept items from two list (divId2 and divId3)
<jscontrols:swap source="divId1" items="select1" styleClassList="list1" selectAllListAction="selectAllList1" selectNoneListAction="selectNoneList1" > <jscontrols:accept source="divId2" swapAction="swapList2ToList1" /> <jscontrols:accept source="divId3" /> </jscontrols:swap>