Permalink
Browse files

Add js to grow form automagically

  • Loading branch information...
1 parent b4b76e0 commit c2efaa08b36109deb41dd0c74c7bbf5208b635cb @namelessjon committed Jul 3, 2010
Showing with 190 additions and 8 deletions.
  1. +12 −8 black_book/templates/edit.html
  2. +2 −0 black_book/templates/layout.html
  3. +22 −0 public/black-book.js
  4. +154 −0 public/jquery-1.4.2.min.js
@@ -11,8 +11,11 @@ <h1>{{new_or_edit}} {{name}}</h1>
</fieldset>
<fieldset id='numbers'>
<legend>Phone Numbers</legend>
- <table>
- <tr><th>Name</th><th>Number</th></tr>
+ <table class='edit-table'>
+ <thead>
+ <tr><th>Name</th><th>Number</th></tr>
+ </thead>
+ <tbody>
{{#numbers}}
<tr>
<td><input type='text' size='20' name='person[numbers][][name]' value='{{name}}' /></td>
@@ -23,13 +26,16 @@ <h1>{{new_or_edit}} {{name}}</h1>
<td><input type='text' size='20' name='person[numbers][][name]' value='' /></td>
<td><input type='text' size='30' name='person[numbers][][number]' value='' /></td>
</tr>
+ </tbody>
</table>
- <a id='add_number' href='#'>Add Number</a>
</fieldset>
<fieldset id='emails'>
<legend>Emails</legend>
- <table>
+ <table class='edit-table'>
+ <thead>
<tr><th>Name</th><th>Email</th></tr>
+ </thead>
+ <tbody>
{{#emails}}
<tr>
<td><input type='text' size='20' name='person[emails][][name]' value='{{name}}' /></td>
@@ -40,12 +46,12 @@ <h1>{{new_or_edit}} {{name}}</h1>
<td><input type='text' size='20' name='person[emails][][name]' value='' /></td>
<td><input type='email' size='30' name='person[emails][][email]' value='' /></td>
</tr>
+ </tbody>
</table>
- <a id='add_email' href='#'>Add Email</a>
</fieldset>
<fieldset id='addresses'>
<legend>Addresses</legend>
- <ul>
+ <ul class='edit-list'>
{{#addresses}}
<li>
<dl class='address-list'>
@@ -77,8 +83,6 @@ <h1>{{new_or_edit}} {{name}}</h1>
</dl>
</li>
</ul>
- <a id='add_address' href='#'>Add Address</a>
</fieldset>
- <input type='hidden' name='foo' value='bar' />
<input type='submit' value='{{button_text}}' />
</form>
@@ -8,5 +8,7 @@
<div id='content'>
{{{yield}}}
</div>
+ <script type='text/javascript' src='/jquery-1.4.2.min.js' ></script>
+ <script type='text/javascript' src='/black-book.js' ></script>
</body>
</html>
View
@@ -0,0 +1,22 @@
+// Javascript
+// Jonathan D. Stott <jonathan.stott@gmail.com>
+(function ($) {
+
+}(jQuery));
+
+$(document).ready(function () {
+ $('table.edit-table tbody').delegate('tr:last-child input', 'change', function () {
+ var tr = $(this).parents('tr'),
+ trClone;
+ trClone = tr.clone(false);
+ trClone.find('input').val('');
+ tr.after(trClone);
+ });
+ $('ul.edit-list').delegate('li:last-child input, li:last-child textarea', 'change', function () {
+ var li = $(this).parents('li'),
+ liClone;
+ liClone = li.clone(false);
+ liClone.find('input,textarea').val('');
+ li.after(liClone);
+ });
+});
Oops, something went wrong.

0 comments on commit c2efaa0

Please sign in to comment.