[英]Hiding fields with Django crispy forms
I have the following in my forms.py : 我的form.py中包含以下内容:
class DocumentsForm(forms.ModelForm):
class Meta:
model = Documents # Your User model
fields = ['EMAIL', 'OWNERFULLNAME', 'OWNERSTREET', 'OWNERCITY', 'OWNERSTATE', 'OWNERZIP', 'DATE']
labels = {
'EMAIL': 'Owner Email',
'OWNERFULLNAME': 'Owner Address',
'OWNERSTREET': 'Owner Street',
'OWNERCITY': 'Owner City ',
'OWNERSTATE': 'Owner State',
'OWNERZIP': 'Owner Zip',
'DATE': I WANT THIS AS A HIDDEN FIELD',
# 'captcha': "Enter captcha"
}
helper = FormHelper()
helper.form_method = 'POST'
helper.form_action = "/contact/"
helper.form_id = 'form' # SET THIS OR BOOTSTRAP JS AND VAL.JS WILL NOT WORK
helper.add_input(Submit('Submit', 'Submit', css_class='btn-primary'))
I want to Hide the date field, In the docs ( https://django-crispy-forms.readthedocs.io/en/latest/layouts.html ) , this can be handled using the 我想隐藏日期字段,在docs( https://django-crispy-forms.readthedocs.io/en/latest/layouts.html )中,可以使用
Field('field_name', type="hidden")
Can this be done using the format above using the formhelper class ( https://django-crispy-forms.readthedocs.io/en/latest/api_helpers.html ) ? 可以使用formhelper类( https://django-crispy-forms.readthedocs.io/en/latest/api_helpers.html )使用上述格式来完成此操作吗?
I was able to add: 我能够添加:
helper.layout = Layout(
Field('DATE', type="hidden"))
and it worked. 而且有效。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.