2014-02-28 1 views
1

사용자 지정 템플릿을 사용하여 crispy_forms를 통해 만드는 양식 내에 기본 오류를 표시하는 데 문제가 있습니다. 즉,이 필드는 필수 입력란입니다. 두 필드에 대해 존재하지 않습니다.crispy_forms 및 사용자 지정 템플릿을 사용하는 동안 장고 오류가 발생했습니다.

 ... 
     start_time = forms.TimeField(label='Start Time', required=True, input_formats=[TIME_FORMAT]) 
     end_time = forms.TimeField(label='End Time', required=True, input_formats=[TIME_FORMAT]) 
     ... 
     Field('end_date', placeholder='dd/mm/yyyy'), 
     Field('start_time', placeholder='hh:mm (pm/am)', template="appointments/datetimefield.html"), 
     Field('end_time', placeholder='hh:mm (pm/am)', template="appointments/datetimefield.html"), 

하고 깨끗한 방법을 here을 저장 :

참조하십시오

, 여기

here 폼의 초기화 코드의 마지막

, 사용자 정의 템플릿 :

{% 부하 crispy_forms_field %}

<div id="div_{{ field.auto_id }}" class="form-group{% if field.errors %} has-error{% endif %}"> 

{% if field.label and form_show_labels %} 
<label for="{{ field.id_for_label }}" class="control-label {{ label_class }}{% if field.field.required %} requiredField{% endif %}"> 
    {{ field.label|safe }}{% if field.field.required %}<span class="asteriskField">*</span>{% endif %} 
</label> 
{% endif %} 

<div class="controls col-xs-8 col-md-9 col-lg-9"> 
    {% crispy_field field %} 
</div> 
</div> 

답변

1

템플릿에 오류를 표시해야합니다. 파삭 파삭 한 모양에는 과실을 포함 할 수있는 템플렛이있다 : {% include 'bootstrap3/layout/help_text_and_errors.html' %} (당신이 bootstrap 3를 사용하고있는 경우에).

그래서 사용자 지정 서식 파일은 다음과 같이 수 있습니다 :

<div id="div_{{ field.auto_id }}" class="form-group{% if field.errors %} has-error{% endif %}"> 

{% if field.label and form_show_labels %} 
<label for="{{ field.id_for_label }}" class="control-label {{ label_class }}{% if field.field.required %} requiredField{% endif %}"> 
    {{ field.label|safe }}{% if field.field.required %}<span class="asteriskField">*</span>{% endif %} 
</label> 
{% endif %} 

<div class="controls col-xs-8 col-md-9 col-lg-9"> 
    {% crispy_field field %} 
    {% include 'bootstrap3/layout/help_text_and_errors.html' %} 
</div> 
</div> 
+0

제안 해 주셔서 감사합니다.하지만 필드 아래의 텍스트는 검은 색으로 빨간색으로 표시되지 않습니다. http://imgur.com/AZJL9SI –

+0

오, 이런. 부트 스트랩 3을 사용하고 있습니까? include는'bootstrap/layout/help_text_and_errors.html'이 아닌'bootstrap3/layout/help_text_and_errors.html'이어야합니다. 내 대답을 업데이트했습니다. – jproffitt

+0

트릭을 해 주셔서 감사합니다. 많은 감사를드립니다. –

0

은 아마 당신은 crispy_forms의 버전을 확인하고 업데이트해야합니다.

또한이 문제는 crispy_forms == 1.3.2에서 발생했습니다. 그러나 crispy_forms를 1.4.0으로 업데이트하면 문제가 사라졌습니다.

사실, 난 crispy_forms의 == 1.3.2 설치할 때 단지 bootstrapuni_form 폴더가 crispy_forms/templatesbootstrap3 폴더되지 않은 것으로 나타났다.

관련 문제