초급 단계의 작업입니다. 나는 다음과 같은 예제를 사용하여 장고에 달력 위젯을 구현하기 위해 노력하고 있습니다 : http://djangosnippets.org/snippets/1629/
캘린더 버튼이 잘못 작동합니다.
는 나는 이미 제출 버튼이있는 폼 내부에이 달력을 걸었습니다. 문제는 캘린더 위젯을 표시하는 데 내 캘린더 버튼이 이 아닌 내 양식을 제출한다는 것입니다. 달력 아이콘과 버튼이 제대로 표시되고 에 방화 광목의 올바른 코드가 있다는 것을 볼 수 있지만 그게 그 것입니다.
내가 정말로 필요한 것은 ModelForm과 함께가는 쉬운 달력입니다. 나는 처럼 JSCal2를 캘린더 작업만큼 많이 사용하지 않는다.
내 calbutton이 내 양식을 제출하는 이유는 무엇입니까? 위젯을 표시하고 제대로 작동하게하려면 어떻게해야합니까? 다른 유용한 제안으로 쉽게 캘린더를받을 수 있습니까?
-------------widgets.py ---------------------
calbtn = u"""<input id="calendar-inputField" /><button id="calendar-trigger"> <img src="%simages/calbutton.gif" alt="calendar" id="%s_btn"
style="cursor: pointer; height="20"; width="20"; border: 1px solid #8888aa;" title="Select date and
time"
onmouseover="this.style.background='#444444';"
onmouseout="this.style.background=''" />
</button>
<script type="text/javascript">
Calendar.setup({
trigger : "calendar-trigger",
inputField : "calendar-inputField"
inputField : "%s",
ifFormat : "%s",
button : "%s_btn",
singleClick : true,
showsTime : true
onSelect : function() { this.hide() }
});
</script>"""
class DateTimeWidget(forms.widgets.TextInput):
dformat = '%Y-%m-%d %H:%M'
def render(self, name, value, attrs=None):
# Same as the example ...
def value_from_datadict(self, data, files, name):
# Same as the example ...
class Media:
css = {
'all': ('/static/calendar/gold.css',)
}
js = ('/static/calendar/jscal2.js',
'/static/calendar/en.js',
)
- ----------- forms.py ----------------
class CustMainForm(ModelForm):
lastName = forms.CharField(max_length=20)
firstName = forms.CharField(max_length=20)
class Meta:
model = Customer
fields = ('notes', 'saleDate')
widgets = {
'notes': Textarea(attrs={'cols': 80, 'rows': 20}),
'saleDate' : DateTimeWidget(), # shown above
}