#22969: Forms show_hidden_initial not is_valid() and fix => lost changes in 
valid
fields
-------------------------------------+-------------------------------------
     Reporter:  dibrovsd@…           |                    Owner:  nobody
         Type:  Bug                  |                   Status:  new
    Component:  Forms                |                  Version:  1.6
     Severity:  Normal               |               Resolution:
     Keywords:  Form                 |             Triage Stage:
  show_hidden_initial changed_data   |  Unreviewed
    Has patch:  1                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  1
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Changes (by dibrovsd@…):

 * needs_better_patch:  0 => 1
 * has_patch:  0 => 1


Comment:

 fix:
 django.forms.forms.BoundField

 add method

 {{{
 def value_for_hidden(self, widget):
     u"""
     when form is bound, then get value from initial-field form.data (not
 from field)
     otherwise: if form is not valid, initial_value copy from value
                and lost field from changed_data when send repaired form
     """
     if self.form.is_bound:
         data = widget.value_from_datadict(self.form.data, self.form.files,
 self.html_initial_name)
         return self.field.prepare_value(data)
     else:
         return self.value()
 }}}

 fix method as_widget (end of method)

 {{{
     name = self.html_name
     value = self.value()
 else:
     name = self.html_initial_name
     value = self.value_for_hidden(widget)

 return widget.render(name, value, attrs=attrs)
 }}}

-- 
Ticket URL: <https://code.djangoproject.com/ticket/22969#comment:2>
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 unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/076.80afa65508509dc7a065caf3eed82882%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to