這個問題中有很多移動部分,但如果您對它的任何部分有任何洞察,那麼將不勝感激。在Bootstrap Modal中使用django脆皮形式的AJAX反饋表
我想建立一個反饋表單,其行爲與人們預期的一樣。當用戶點擊頁面右下方的反饋按鈕時,它會啓動引導模式。該模式有一個django脆皮形式,提交或返回按下提交按鈕時無效的字段。
首先,我有我的反饋按鈕:
{% load crispy_forms_tags %}
.feedback-button {
position: fixed;
bottom: 0;
right: 30px;
}
<div class='feedback-button'>
<a class="btn btn-info" href="#feedbackModal" data-toggle="modal" title="Leave feedback" target="_blank">
<i class="icon-comment icon-white"></i>
Leave feedback
</a>
</div>
<div class="modal hide" id="feedbackModal" tabindex="-1" role="dialog" aria-labelledby="feedbackModalLabel" aria-hidden="true">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">x</button>
<h3 id="feedbackModalLabel">Contact Form</h3>
</div>
<div class="modal-body">
{% crispy feedback_form feedback_form.helper %}
</div>
<div class="modal-footer">
<button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
<button class="btn btn-primary">Submit</button>
</div>
</div>
接下來,我有我的方式:
class Feedback(models.Model):
creation_date = models.DateTimeField("Creation Date", default=datetime.now)
topic = models.CharField("Topic", choices = TOPIC_CHOICES, max_length=50)
subject = models.CharField("Subject", max_length=100)
message = models.TextField("Message", blank=True)
sender = models.CharField("Sender", max_length=50, blank=True, null=True)
def __unicode__(self):
return "%s - %s" % (self.subject, self.creation_date)
class Meta:
ordering = ["creation_date"]
verbose_name = "Feedback"
verbose_name_plural = "Feedback"
class Crispy_ContactForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
self.helper = FormHelper()
self.helper.layout = Layout(
Fieldset(
Field('topic', placeholder='Topic', css_class='input-medium'),
Field('subject', placeholder='Subject', css_class='input-xlarge'),
Field('message', placeholder='Message', rows='5', css_class='input-xlarge'),
Field('sender', placeholder='Sender', css_class='input-xlarge'),
),
)
self.helper.form_id = 'id-Crispy_ContactForm'
self.helper.form_method = 'post'
super(Crispy_ContactForm, self).__init__(*args, **kwargs)
class Meta:
model = Feedback
exclude = ['creation_date']
我試圖忽略傳說中的香脆形式,因爲如果我有吧,模態似乎有兩個表格標題。但是在鬆脆的形式佈局中省略了這個圖例,導致字段出現亂序。
所以我留下了幾個問題:
- 總的來說,我要對這個正確的方式?
- 如果我將模式的提交按鈕連接到AJAX,我該如何去檢查 表單的錯誤檢查?
- 是否有更好的方式顯示 bootstrap模式中的脆皮形式?