#22969: Forms show_hidden_initial not is_valid() and fix => lost changes in 
valid
fields
-------------------------+-------------------------------------------------
     Reporter:           |      Owner:  nobody
  dibrovsd@…             |     Status:  new
         Type:  Bug      |    Version:  1.6
    Component:  Forms    |   Keywords:  Form show_hidden_initial
     Severity:  Normal   |  changed_data
 Triage Stage:           |  Has patch:  0
  Unreviewed             |      UI/UX:  0
Easy pickings:  0        |
-------------------------+-------------------------------------------------
 if use show_hidden_initial as initial and have some error fields
 form.is_valid() == False
 django set initial other (valid) fields from data
 and in next step (user fix form errors) django lost changed valid fields
 from changed_data


 {{{
 from django.forms import Form, CharField

 class MyForm(Form):

     req_field = CharField(show_hidden_initial=True, required=True)
     notreq_field = CharField(show_hidden_initial=True)

 data = {
     'req_field': '', 'initial-req_field': '',
     'notreq_field': '12', 'initial-notreq_field': '',
 }

 # i can't use initial from database.
 # other user can change some field and django revert unchange field back
 # user 1: open form (field_1 is "1")
 # user 2: change field_1 to "2"
 # user 1 change field_2 to "1111" and
 # user 1 send unchange (field_1 is "1") initial value field_1 == "2" (user
 2 change it)
 # django mark field_1 as change from 2 to 1 back

 form = MyForm(data=data)
 assert(form.is_valid(), False)  # req_field error

 # show invalid form and set: initial-notreq_field = 12 (why???)
 # in next send form this field not in changed_data
 for field in form.visible_fields():
     print field
 # django action: set initial-notreq_field = 12
 data['initial-notreq_field'] = '12'  #

 # user action: fix error
 data['req_field'] = '12'
 form = MyForm(data=data)
 print form.is_valid()

 for change_field in form.changed_data:
     print 'change', change_field, form.cleaned_data[change_field]
 # oops! lost change in notreq_field
 }}}

-- 
Ticket URL: <https://code.djangoproject.com/ticket/22969>
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/061.aeb3f838824e78f0ae09d73eff87bd34%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to