Commits

Anonymous committed da15dd6

[soc2009/admin-ui] One step further to adding inlines using javascript.

This time, we clone the first hidden extra-inline field, append it to the inline list, and update its id. This is actually a pretty terrible way to add inlines, but it serves the purpose of showing what an addition will look like.

Comments (0)

Files changed (2)

django/contrib/admin/options.py

             'root_path': self.admin_site.root_path,
             'app_label': opts.app_label,
         }
-        #import ipdb; ipdb.set_trace()
         context.update(extra_context or {})
         return self.render_change_form(request, context, change=True, obj=obj)
     change_view = transaction.commit_on_success(change_view)

django/contrib/admin/templates/admin/edit_inline/stacked.html

 {% load i18n %}
-<div class="inline-group">
+<div class="inline-group" id="{{ inline_admin_formset.opts.verbose_name}}-group">
   <h2>{{ inline_admin_formset.opts.verbose_name_plural|title }}</h2>
 {{ inline_admin_formset.formset.management_form }}
 {{ inline_admin_formset.formset.non_form_errors }}
     
     // clicking on the "add" link will add a blank form to add a new inline object
     $('#' + id_prefix + "-add").click(function() {
+        {# TODO Zain: this will not work if extra = 0 for the inline #}
         total_forms++;
-        $('#' + id_prefix + (total_forms)).show();
+        
+        // clone the first hidden extra-inline field and append it to the inline list
+        $('#' + id_prefix + (initial_forms + 1)).clone().fadeIn('normal')
+            .insertAfter('#' + id_prefix + "-group .inline-related:last")
+            .attr("id", id_prefix + total_forms)
+        
+        return false;
     });
 });
 </script>