asaglimbeni / django-datetime-widget

Bootstrap django-datetime-widget is a simple and clean widget for DateField, Timefiled and DateTimeField in Django framework. It is based on Bootstrap datetime picker, supports both Bootstrap 3 and Bootstrap 2
Other
219 stars 125 forks source link

Can't set attrs of widget #40

Open swasher opened 10 years ago

swasher commented 10 years ago

Hi asaglimbeni! Your widget great and work fine with default settings. But attrs dont work for me. I'm trying do it in this way:

class FilterForm(forms.ModelForm):
   from_date = forms.DateField(
       widget=DateWidget(
           attrs={'weekStart': '3', 'autoclose': 'false'}, 
           usel10n=True, 
           bootstrap_version=3
       ),
       required=False
   )
   class Meta:
       model = Grid
       fields = ['from_date']

Nothing happens at any settings, widget run as default. Localization dont work too. In setting.py

LANGUAGE_CODE = 'ru-RU'
TIME_ZONE = 'Europe/Kiev'
USE_I18N = True
USE_L10N = True
USE_TZ = True

Please help me tuning widget! Best regards

asaglimbeni commented 10 years ago

Hi swasher the rigth way to set the optiones in the javascript object is that :

dateTimeOptions = { 'format': 'dd/mm/yyyy HH:ii P', 'autoclose': 'true', 'showMeridian' : 'true' } widgets = { 'datetime': DateTimeWidget(options = dateTimeOptions) }

all the options supported are reported in the documentation, https://github.com/asaglimbeni/django-datetime-widget#options

Let me knwo if this is what you need . Cheers

swasher commented 10 years ago

Sorry but no success. Can you add option setup on your demo page? And if you have time, may be you can inspect my forms here https://github.com/swasher/pdfupload/blob/master/workflow/forms.py

Thanks for your help.

asaglimbeni commented 10 years ago

Thank you for the suggest I will add an example also with the options paramter in any case you example have some strange things. fist of all , why are you using a Datewidget with a 'format': 'dd/mm/yyyy HH:ii P' ? you define the widget two times for the same field, where do you want to define it ? it is enagth one time I guess the second time is ignored becuase you define it directly ni the fileld without hte options parameter. please decide one place where you want to instantiate the widget.