source: trunk/web-app/js/dynamicOneToMany.js @ 877

Last change on this file since 877 was 798, checked in by gav, 14 years ago

Svn merge -r752:r797 branches/features/taskProcedureRework into trunk/.

File size: 1.2 KB
Line 
1
2// Depends on jQuery.
3
4// Add a child by cloning a template and appending to wrapper element.
5// Used with a parent and LazyList of children (One-to-Many).
6// Since javascript has no pointers the childCount source var must be incremented by the calling code.
7// @param wrapperId The id of the wrapper element, e.g: div or tbody.
8// @param cloneId The id of the element to clone.
9// @param lazyList The name of the LazyList.
10// @param fields A list of fields in the clone that need name and id set.
11// @param focusField Which field in the fields list to focus on after adding.
12// @param childCount The current child count, used to set LazyList index, remember to increment!
13function addChild(wrapperId, cloneId, lazyList, fields, focusField, childCount){
14
15    var clone = jQuery("#"+cloneId).clone();
16    clone.attr('id', lazyList+childCount);
17    var htmlId = lazyList+'['+childCount+'].';
18
19    var fieldsMap = {};
20    jQuery.each(fields, function(index, field) {
21        fieldsMap[field] = clone.find('[id$="'+field+'"]');
22        fieldsMap[field].attr('id',htmlId + field)
23                                    .attr('name',htmlId + field);
24    });
25
26    jQuery("#"+wrapperId).append(clone);
27    clone.show();
28    fieldsMap[focusField].focus();
29}
Note: See TracBrowser for help on using the repository browser.