python - Django Form Wizard persistent initial data between steps -


i'm using django form wizard in project. want allow users provide initial data specific field , want make field initial data provided disabled.

problem when user clicks button initial data erased.

for example form(initial data set second step) enter image description here can see fine here, form fields disabled , value selected. click next.

enter image description here click next , second step without problems if click back.. enter image description here

form fields still disabled value gone!

the code i'm using goes (relevant part):
form

choices=[('one','choice 1'),          ('two','choice 2'),          ('three','choice 3'),          ('four','choice 4'),         ]  class bookingform1(forms.form):     """ select reservation type"""     sko = forms.choicefield(choices=choices, widget=forms.radioselect()) 

wizard

def get_form(self, step=none, data=none, files=none):         form = super(presentview, self).get_form(step, data, files)         step = step or self.steps.current          initial = {             'sko': {                 'initial':'two'             }         }          field in initial:             try:                 form.fields[field].widget.attrs['readonly'] = true                 form.fields[field].widget.attrs['disabled'] = true                 form.fields[field].required = false                 form.fields[field].initial = initial[field]['initial']             except:                 pass 

any ideas appreciated!

the way able solve removing fields choicefield type objects.

 field in initial:             try:                 field_o = form.fields[field]                 # remove choices if choice field                 if type(field_o) == forms.fields.choicefield:                     field_o.choices = [(key, value) key,value in field_o.choices if key == initial[field]['initial']]                 else:                     field_o.widget.attrs['readonly'] = true                  field_o.initial = initial[field]['initial']             except:                 pass 

Comments

Popular posts from this blog

java - Static nested class instance -

c# - Bluetooth LE CanUpdate Characteristic property -

JavaScript - Replace variable from string in all occurrences -