问题描述
今天有一个陌生人。
我有一个非常基础的项目。一个表单,并添加到我有一个内联表格。这是作者的书籍。
I've a very basic project. A form and added to that I have an inline form. It's books to authors.
当表单加载(/ authors / create /)时,我有一个作者姓名,下面我有一个表单,我可以向该作者添加书籍
When the form loads(/authors/create/) I have a author name and underneath I have a form where I can add books to that author.
为了能够有动态内联(可以在表单上添加或删除)我使用。
To be able to have dynamic inlines(able to add or remove on the form) I'm using http://code.google.com/p/django-dynamic-formset/.
我现在的问题是,当我添加一个新的内联时,内联表单的所有日期戳记(发布日期的字段)将停止工作。
My problem now is that when I add a new inline, all my datepickers(for the date published fields) for the inline form stops working.
为什么和如何解决这个问题?
推荐答案
我相信有更干净,更聪明的方法来做。但是工作证明的概念:
I am sure there is cleaner and more clever way to do it. But working proof of concept:
function renewDatePickers() {
$('.datepicker').datepicker('destroy');
$(".datepicker").datepicker({dateFormat: 'yy-mm-dd'});
}
$(renewDatePickers);
$(function() {
$('.form-row.inline.{{ book_form.prefix }}').formset({
prefix: '{{ book_form.prefix }}',
added: renewDatePickers // Event -- read inline docs
});
})
并将您的JS代码从 base.html
转到 author_form.html
And take Your JS code from base.html
to author_form.html
这篇关于在我的表单集中添加一个新的内联时,我的datepickers停止工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!