简体   繁体   中英

django setting initial value on form for DateTimeField to '--------'

I want the expire date to remain required, so I don't want to use Required=False. However, I want it to initially show as '-------' for each of the three dropdowns (month, day, year) instead of January 1 2017 for the dropdowns.

from django import forms 

class LicenseCreateForm(forms.ModelForm): 
     expire= forms.DateTimeField(widget=forms.SelectDateWidget(),)

I ended up just doing doing it with jquery.

$("#id_expire_month").prepend("<option value='---' selected='selected'></option>");
$("#id_expire_day").prepend("<option value='---' selected='selected'></option>");
$("#id_expire_year").prepend("<option value='---' selected='selected'></option>");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM