我在调查表单中有9个隐藏的单选按钮,每个按钮都附有可见图像。这个想法是用户应该在移动到调查的下一页之前选择其中一个图像。然后,应用程序将存储提交图像的名称。
如果可能,我想强制forms.HiddenInput
,以便用户 选择其中一个图片,然后才能进入下一页
我知道这听起来有点像一个愚蠢的问题,但有人知道这是否可行以及如何做到这一点?感谢
forms.py
class SurveyFormDV4(forms.ModelForm):
class Meta:
model = Person
fields = ['DV_positive']
widgets = {'DV_positive' : forms.HiddenInput}
models.py
class Person(models.Model):
....
....
DV_positive = models.CharField(null=True, max_length=100, blank=True)
def __unicode__(self):
return self
注意:如果我没有在此处传递blank=True
,那么我是否会选择不选择的页面。
views.py
class SurveyWizardOne(SessionWizardView):
def get_context_data(self, form, **kwargs):
context = super(SurveyWizardOne, self).get_context_data(form, **kwargs)
step = int(self.steps.current)
....
....
elif step == 22:
context.update({'first_image' : images[0],
'second_image' : images[1],
'third_image' : images[2],
....
....
})
wizard_form.html
{% if wizard.steps.current in dv_nine_positive %}
<div id="dialog-message" title="Positive Bias">
<p>
Please select your favorite image
</p>
</div>
<script>
$( "#dialog-message" ).dialog({
autoOpen: true,
modal: true,
buttons: {
Ok: function() {
$( this ).dialog( "close" );
}
}
});
$( "#opener" ).click(function() {
$( "#dialog" ).dialog( "open" );
});
</script>
<div class="DV_image_row">
<div class="DV_image_left">
<label class="radio_hidden">
<input type="radio" name="final_dv" value="1"/>
<img src="{% static "survey/images/pathone/" %}{{first_image}}" height="300" width="250"/>
</label>
</div>
<div class="DV_image_centre">
<label class="radio_hidden">
<input type="radio" name="final_dv" value="2"/>
<img src="{% static "survey/images/pathone/" %}{{second_image}}" height="300" width="250"/>
</label>
</div>
<div class="DV_image_right">
<label class="radio_hidden">
<input type="radio" name="final_dv" value="3"/>
<img src="{% static "survey/images/pathone/" %}{{third_image}}" height="300" width="250"/>
</label>
</div>
</div>
<div class="DV_image_row">
<div class="DV_image_left">
....
....
<div class="submit_buttons">
{% if wizard.steps.prev %}
<button class="btn" name="wizard_goto_step" type="submit" value="{{ wizard.steps.first }}">{% trans "First Step" %}</button>
<button class="btn" name="wizard_goto_step" type="submit" value="{{ wizard.steps.prev }}">{% trans "Prev Step" %}</button>
{% endif %}
<input class="btn btn-default btn-success" type="submit" name="submit" value="{% trans "Next" %}"/>
</div>
{% endif %}