Ticket #10557: form_wizard_prev_fields.diff

File form_wizard_prev_fields.diff, 3.6 KB (added by Matthew Flanagan <mattimustang@…>, 16 years ago)

patch for class and docs

  • django/contrib/formtools/wizard.py

     
    88
    99from django import forms
    1010from django.conf import settings
     11from django.forms.forms import BoundField
    1112from django.http import Http404
    1213from django.shortcuts import render_to_response
    1314from django.template.context import RequestContext
     
    102103        old_data = request.POST
    103104        prev_fields = []
    104105        if old_data:
    105             hidden = forms.HiddenInput()
    106             # Collect all data from previous steps and render it as HTML hidden fields.
     106            # Collect all data from previous steps as bound fields.
    107107            for i in range(step):
    108108                old_form = self.get_form(i, old_data)
    109109                hash_name = 'hash_%s' % i
    110                 prev_fields.extend([bf.as_hidden() for bf in old_form])
    111                 prev_fields.append(hidden.render(hash_name, old_data.get(hash_name, self.security_hash(request, old_form))))
    112         return self.render_template(request, form, ''.join(prev_fields), step, context)
     110                prev_fields.extend([bf for bf in old_form])
     111                hash_field = forms.Field(initial=old_data.get(hash_name,
     112                    self.security_hash(request, old_form)))
     113                bf = BoundField(forms.Form(), hash_field, hash_name)
     114                prev_fields.append(bf)
     115        return self.render_template(request, form, prev_fields, step, context)
    113116
    114117    # METHODS SUBCLASSES MIGHT OVERRIDE IF APPROPRIATE ########################
    115118
  • docs/ref/contrib/formtools/form-wizard.txt

     
    141141Next, you'll need to create a template that renders the wizard's forms. By
    142142default, every form uses a template called :file:`forms/wizard.html`. (You can
    143143change this template name by overriding
    144 :meth:`~django.contrib.formtools.wizard..get_template()`, which is documented
     144:meth:`~django.contrib.formtools.wizard.get_template()`, which is documented
    145145below. This hook also allows you to use a different template for each form.)
    146146
    147147This template expects the following context:
     
    152152    * ``step_count`` -- The total number of steps.
    153153    * ``form`` -- The :class:`~django.forms.forms.Form` instance for the
    154154      current step (either empty or with errors).
    155     * ``previous_fields`` -- A string representing every previous data field,
    156       plus hashes for completed forms, all in the form of hidden fields. Note
    157       that you'll need to run this through the
    158       :meth:`~django.template.defaultfilters.safe` template filter, to prevent
    159       auto-escaping, because it's raw HTML.
     155    * ``previous_fields`` -- A list containing every previous data field,
     156      plus hashes for completed forms, all in the form of regular fields. Note
     157      that you'll need to call :meth:`as_hidden` on each field to prevent
     158      them from appearing in your forms.
    160159
    161160It will also be passed any objects in :data:`extra_context`, which is a
    162161dictionary you can specify that contains extra values to add to the context.
     
    182181    {{ form }}
    183182    </table>
    184183    <input type="hidden" name="{{ step_field }}" value="{{ step0 }}" />
    185     {{ previous_fields|safe }}
     184    {% for field in previous_fields %}{{ field.as_hidden }}{% endfor %}
    186185    <input type="submit">
    187186    </form>
    188187    {% endblock %}
Back to Top