At some point, I need to display the attribute "disabled" (greyed out by disabled="disabled" ) of type "select" . As indicated in the standard (xhtml and html4), inputs of type "select" cannot have the attribute "readonly" . Please note that this is for presentation purposes only, the actual value should end in POST. So here is what I am doing (quoting part of form declaration in django):
from django import forms _choices = ['to be', 'not to be'] class SomeForm(forms.Form): field = forms.ChoiceField(choices=[(item, item) for item in _choices], widget=forms.HiddenInput())
Then it is initialized as follows:
initial_val = 'to be' form = SomeForm(ititial={'field':initial_val, 'mock_field':initial_val})
And everything's good. Well, until the form is validated and one of the other fields validates. When this happens, the form reloads and the values ββare saved, but not one of the "mock_field" - it was never submitted (it was disabled). So it has not survived. Although this does not affect data integrity, it is still not well stated.
Is there a way to save this field with a minimum number of hackers? The form is part of django.contrib.formtools.FormWizard , and the initial values ββ(and some fields) are generated dynamically. In principle, a lot of things are already happening, it would be great if there were no unnecessary things.
python django django-forms
shylent
source share