﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
18988	initialization of hidden_initial_fields after a form was bound	its@…	nobody	"After a failed form validation this forms hidden_initial-fields (rendered via the field argument show_hidden_initial=True) will be rendered containing the submitted data of the corresponding regular fields not the data the hidden_initial_fields have submitted

This might cause confusion because: if the form was not saved the value was not saved in the database but is now considered as current db-state in the hidden_initial_field
If a succesive submit is triggered the form will now not identify a form.has_changed-event for the corresponding field

IMHO the hidden_initial_field should recieve its POST/GET data from the hidden_initial_field-data instead of the POST/GET data from the original field after a submit



--how to reproduce
-field ('label') has the argument show_hidden_initial=True
-open the view with an instance from the database
-change the value of the label field and save -> form will be declared invalid and form.label_initial will contain the new value despite that the form could not be saved
-in addition if save is clicked again the form is valid and form.changed_data will be empty


This problem occurred in version 1.2 but considering the implementation of BoundField this will also happen in version 1.4


{{{



class MyModel(models.Model)
    label = models.CharField()
    
    
class MyModelForm(forms.Form)
    def __init__(*args, **kwargs):
        super(MyModelForm, self).__init__(*args, **kwargs)
        for f in self.fields.keys():
            self.fields[f].show_hidden_initial = True
    
    class Meta:
        model = MyModel
    
    def clean(self):
        
        cleaned_data = super(MyModelForm, self).clean()
        
        if self.changed_data:
            self._errors['label'] = ErrorList(['form has changed'])
            
        return cleaned_data

        
def myView(request, modelId=None):
    
    if modelId:
        instance = MyModel.objects.get(pk=modelId)
    else:
        instance = None
        
    if request.method == 'POST':
        form = MyModelForm(request.POST, instance=instance)
        
        if form.is_valid():
            instance = form.save()
            return HttpResponse('Success')
    else:
        form = MyModelForm(instance=instance)
        
    template = '<FORM method=""POST"" enctype=""application/x-www-form-urlencoded""><table>{{form}}</table><input method=""POST"" name=""submit"" type=""submit"" value=""Save""\></Form>'
    
    t = template.Template(output)
    c = template.Context({'form':form})
    return t.render(c)          


}}}
"	Bug	closed	Forms	1.2	Normal	duplicate	forms, show_hidden_initial, change_data		Unreviewed	0	0	0	0	0	0
