I have created a formset with forms. Each form has several fields that must be displaid and must contain initial data. I have created the fields as disabled and passed initial data in the formset. This woks fine for the get method but in case there is an error the bound form returned by the post method does not show the initial values.
What should I do for the initial data to be included in the data returned into the Post?
This is not a “Django” issue. Per the HTML specifications, a disabled field is not included in the POST data.
Since the server already has the data, is there a reason you are looking for it to be submitted in the form? (You could render that data as HTML text rather than as an input form.)
Depending upon the specifics of the situation, there are other options as well. For example, there’s nothing that requires you to post data to the same form as what was rendered on the GET.
Thank you for your answer. Yes there is a reason for submitting it into the POST. The form is for the user to select a set of objects amongst a list of them. Each selected object must be named. In case of error, the invalid form is submitted again. The disabled fields are information which are required by the user to choose which object to select.
I suppose I could render these fields as HTML text but I have zero knowledge about HTML and this is why I chose to include them in the from!…. I will look into it later.
I set the widget attributes to readonly and this seems to be OK for the moment..