Opened 15 years ago

Closed 15 years ago

Last modified 13 years ago

#11432 closed Uncategorized (duplicate)

prepopulated_fields should work for non-slug fields

Reported by: Flo Ledermann Owned by: nobody
Component: contrib.admin Version: 1.0
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I repeatedly have the use case where a CharField should be autopopulated from another one (classical example is a title and a headline, where the headline should be initialized with the title by default)
When using prepopulated_fields, the current hardcoded behaviour is to URLify the field's contents (this is done in the javascript generated in django/contrib/admin/templates/admin/prepopulated_fields_js.html). Current code (prepopulated_fields_js.html:7):

        if (!e._changed) { e.value = URLify({% for innerdep in field.dependencies %}document.getElementById("{{ innerdep.auto_id }}").value{% if not forloop.last %} + ' ' + {% endif %}{% endfor %}, {{ field.field.field.max_length|default_if_none:"50" }}); }

I replaced this by a hack to see if the field is a RegexField, and if not just copy the concatenated values:

        {# a *lot* of things are named 'field' in django ;) #}
        {% if field.field.field.regex %} 
        if (!e._changed) { e.value = URLify({% for innerdep in field.dependencies %}document.getElementById("{{ innerdep.auto_id }}").value{% if not forloop.last %} + ' ' + {% endif %}{% endfor %}, {{ field.field.field.max_length|default_if_none:"50" }}); }
        {% else %}
        if (!e._changed) { e.value = {% for innerdep in field.dependencies %}document.getElementById("{{ innerdep.auto_id }}").value{% if not forloop.last %} + ' ' + {% endif %}{% endfor %}; }
        {% endif %}

I guess you guys have better ideas how to put this on a more solid basis, but I wanted to share the requirement and code with you.

Change History (2)

comment:1 by James Bennett, 15 years ago

Resolution: duplicate
Status: newclosed

Duplicate of #4509. Please search existing tickets before filing new tickets.

comment:2 by Aymeric Augustin, 13 years ago

Easy pickings: unset
Severity: Normal
Type: Uncategorized
UI/UX: unset

#16226 is a duplicate.

Note: See TracTickets for help on using tickets.
Back to Top