#13068: The "Add another [inline object]" javascript doesn't respect
prepopulated_fields settings
-------------------------------------+-------------------------------------
               Reporter:  hejsan     |          Owner:  seanbrant
                   Type:             |         Status:  reopened
  Uncategorized                      |      Component:  contrib.admin
              Milestone:  1.2        |       Severity:  Normal
                Version:  1.3        |       Keywords:  prepopulated_field
             Resolution:             |  inline add
           Triage Stage:  Accepted   |      Has patch:  1
    Needs documentation:  0          |    Needs tests:  0
Patch needs improvement:  0          |  Easy pickings:  0
-------------------------------------+-------------------------------------
Changes (by stan <stanislas.guerra__at__gmail.com>):

 * status:  closed => reopened
 * severity:   => Normal
 * resolution:  fixed =>
 * version:  SVN => 1.3
 * easy:   => 0
 * keywords:   => prepopulated_field inline add
 * type:   => Uncategorized


Comment:

 I reopen the ticket because It still does not works with the
 ''StackedInline''.

 The problem is in ''initPrepopulatedFields'' javascript function in the
 ''django/contrib/admin/edit_inline/{stacked,tabular}.html'' files and in
 the way the selector are set in the html.

 Having the following in my admin.py:


 {{{
 class CahierInline(admin.StackedInline):
     model = models.Cahier
     extra = 1
     fieldsets = (
         (None, {
             'fields': (('ordre',), ('nom', 'euid', 'valide',),
 'nom_court',)
         }),
         ('périodicité', {
             'fields': ('periodicite', 'jours_de_parution_semaine',
 'jours_de_parution_mois',)
         }),
     )
     prepopulated_fields = {'euid': ('nom',)}

 }}}



 For a TabularInline, the html produced looks like that :


 {{{
 <td class="euid prepopulated_field">
 <input id="id_cahiers-1-euid" class="vTextField" type="text"
 maxlength="50" name="cahiers-1-euid">
 </td>
 }}}

 And with StackedInline :


 {{{
 <div class="form-row nom euid valide prepopulated_field">
   <div class="field-box">
     <label class="required" for="id_cahiers-1-nom">Nom:</label>
     <input id="id_cahiers-1-nom" class="vTextField" type="text"
 maxlength="100" name="cahiers-1-nom">
   </div>
   <div class="field-box">
     <label class="required inline" for="id_cahiers-1-euid">Clé:</label>
     <input id="id_cahiers-1-euid" class="vTextField" type="text"
 maxlength="50" name="cahiers-1-euid">
   </div>
   <div class="field-box">
     <input id="id_cahiers-1-valide" type="checkbox"
 name="cahiers-1-valide" checked="checked">
     <label class="vCheckboxLabel inline"
 for="id_cahiers-1-valide">Valide</label>
   </div>
 </div>
 }}}


 The lookup in ''initPrepopulatedFields'' for the pre-populated input
 cannot works in the last case (and is not possible unless with a crap)
 because the class ''euid'' (''via field.field.name'') is too high in the
 DOM.


 There is at last two way to correct that :

 1. put the ''field.field.name'' class on the div.field-box ;
 2. change the lookup in ''initPrepopulatedFields'' for
 ''django/contrib/admin/edit_inline/{stacked,tabular}.html''.

 I am a bit surprised that we have two different files
 ''admin/edit_inline/{stacked,tabular}.html'' with one using an include to
 render the fieldset and the other doing it ''in-situ'' but having the
 similar bits of javascript.
 Those 2 files being factorizables (at least for the js part), adding some
 differences in the behavior is not the best way so my patch implements the
 first solution.
 I didn't run the test suite so it may break some stuff because the render
 is now like that :


 {{{
 <div class="form-row">
   <div class="field-box nom">
     <label class="required" for="id_cahiers-1-nom">Nom:</label>
     <input id="id_cahiers-1-nom" class="vTextField" type="text"
 maxlength="100" name="cahiers-1-nom">
   </div>
   <div class="field-box euid prepopulated_field">
     <label class="required inline" for="id_cahiers-1-euid">Clé:</label>
     <input id="id_cahiers-1-euid" class="vTextField" type="text"
 maxlength="50" name="cahiers-1-euid">
   </div>
   <div class="field-box valide">...
 </div>

 }}}

-- 
Ticket URL: <http://code.djangoproject.com/ticket/13068#comment:18>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" 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.com/group/django-updates?hl=en.

Reply via email to