Author: sevein
Date: Wed Oct 14 17:55:37 2009
New Revision: 3748

Log:
I forgot to add multiRow.js in the last commit.

Added:
   trunk/web/js/multiRow.js   (contents, props changed)

Added: trunk/web/js/multiRow.js
==============================================================================
--- /dev/null   00:00:00 1970   (empty, because file is newly added)
+++ trunk/web/js/multiRow.js    Wed Oct 14 17:55:37 2009        (r3748)
@@ -0,0 +1,47 @@
+function addNewRow(sender)
+{
+  var table = $(sender).parents('table:first');
+  var lastRow = table.find('tbody tr:last');
+  var newRow = lastRow.clone();
+
+  var lastRowNumber = parseInt(lastRow.find("select, 
input").filter(":first").attr("name").match(/\d/).shift());
+
+  // Input content is removed
+  newRow.find('input, select').each(function(i)
+    {
+      if ($(this).is('input'))
+      {
+        $(this).val('');
+      }
+      else if ($(this).is('select'))
+      {
+        var oldSelect = lastRow.find('input, select').eq(i);
+        var selectedIndex = oldSelect[0].selectedIndex;
+
+        $(this)[0].selectedIndex = selectedIndex;
+      }
+
+      var newName = $(this).attr('name').replace(/\[\d\]/, '[' + 
(lastRowNumber + 1) + ']');
+      $(this).attr('name', newName);
+    });
+
+  table.children('tbody').append(newRow);
+}
+
+/**
+ * On page load, "multiRow" tables are prepared to add as many rows as users 
want
+ */
+Drupal.behaviors.multiRow = {
+  attach: function (context)
+  {
+    $('table.multiRow').each(function () {
+      var tfoot  = '<tfoot>';
+      tfoot     += '<tr>';
+      tfoot     += '<td colspan=' + ($(this).find('tbody tr:first td').length 
+ 1) + '><a href="#" onclick="addNewRow(this); return false;">add new</a></td>';
+      tfoot     += '</tr>';
+      tfoot     += '</tfoot>';
+
+      $(this).append(tfoot);
+    });
+  }
+};

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Qubit Toolkit Commits" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.ca/group/qubit-commits?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to