Wednesday, November 13, 2013

Re: Widget isn't sticking?

Actually you're using something I'd probably not even bother using a widget for.

Really, you probably just want to include the appropriate CSS and JS in your template (although you can use the widget class as well - the key here is that the CSS and JS need to be on your page somewhere).

You then need to trigger the date selector.

Docs show 
  1. $('.datepicker').datepicker()

Which would find all inputs of class 'datepicker'

So we need to set the class on your input.

expiry_date = forms.DateField(widget=CalendarWidget(attrs={'class': 'datepicker'}))

note you can just use the TextInput widget if you're including the CSS/JS in your template. That tends to be what I do unless I'm creating a full featured widget which is pretty rare.

expiry_date = forms.DateField(widget=TextInput(attrs={'class': 'datepicker'}))

On Wednesday, November 13, 2013 1:31:40 PM UTC-8, Lachlan Musicman wrote:
Nothing, unfortunately.

On 14 November 2013 07:37, Jason Arnst-Goodrich <good...@gmail.com> wrote:
> Try:
>
> expiry_date = forms.DateField(widget=CalendarWidget())
>
>
> On Tuesday, November 12, 2013 5:41:27 PM UTC-8, Lachlan Musicman wrote:
>>
>> Hola,
>>
>> I've set up a CalendarWidget as per the docs
>> https://docs.djangoproject.com/en/1.6/topics/forms/media/ and can see
>> correct results in the shell:
>>
>>
>> forms.py
>> ---------
>>
>> class CalendarWidget(forms.TextInput):
>>     class Media:
>>         css = {
>>             'all': (settings.STATIC_URL + 'css/datepicker.css',)
>>         }
>>         js = (settings.STATIC_URL + 'js/bootstrap-datepicker.js',)
>>
>> ...
>>
>> class CarrierWizardForm1(forms.Form):
>>     part_numbers =
>> forms.ModelChoiceField(queryset=PartNumber.objects.all())
>>     expiry_date = forms.DateField(widget=CalendarWidget)
>>
>>
>> shell
>> -------
>>
>> >>> from inventory import forms
>> >>> w = forms.CalendarWidget()
>> >>> print(w.media)
>> <link href="/static/css/datepicker.css" type="text/css" media="all"
>> rel="stylesheet" />
>> <script type="text/javascript"
>> src="/static/js/bootstrap-datepicker.js"></script>
>> >>> f = forms.CarrierWizardForm1()
>> >>> print(f.media)
>> <link href="/static/css/datepicker.css" type="text/css" media="all"
>> rel="stylesheet" />
>> <script type="text/javascript"
>> src="/static/js/bootstrap-datepicker.js"></script>
>>
>>
>> But in the browser I'm not seeing the new widget.
>>
>> What am I doing wrong? Do I have to explicitly pull the assets into
>> the template in question?
>> Am I meant to be explicitly referring to the widget in the template?
>>
>> I note that using the built in SelectDateWidget works fine:
>>
>> from django.forms.extras.widgets import SelectDateWidget
>> class CarrierWizardForm1(forms.Form):
>>     part_numbers =
>> forms.ModelChoiceField(queryset=PartNumber.objects.all())
>>     #expiry_date = forms.DateField(widget=CalendarWidget)
>>     expiry_date = forms.DateField(widget=SelectDateWidget)
>>
>>
>> Cheers
>> L.
>>
>>
>> --
>> From this perspective it is natural that anarchism be marked by
>> spontaneity, differentiation, and experimentation that it be marked by
>> an expressed affinity with chaos, if chaos is understood to be what
>> lies outside or beyond the dominant game or system. Because of the
>> resistance to definition and categorisation, the anarchist principle
>> has been variously interpreted as, rather than an articulated
>> position, "a moral attitude, an emotional climate, or even a mood".
>> This mood hangs in dramatic tension between utopian hope or dystopian
>> nihilism...
>> -----
>> http://zuihitsu.org/godspeed-you-black-emperor-and-the-politics-of-chaos
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users...@googlegroups.com.
> To post to this group, send email to django...@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/24f84c8e-f8bc-4dc0-a519-b1c3d4740d9b%40googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.



--
From this perspective it is natural that anarchism be marked by
spontaneity, differentiation, and experimentation that it be marked by
an expressed affinity with chaos, if chaos is understood to be what
lies outside or beyond the dominant game or system. Because of the
resistance to definition and categorisation, the anarchist principle
has been variously interpreted as, rather than an articulated
position, "a moral attitude, an emotional climate, or even a mood".
This mood hangs in dramatic tension between utopian hope or dystopian
nihilism...
-----
http://zuihitsu.org/godspeed-you-black-emperor-and-the-politics-of-chaos

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/7a28eabb-438f-4951-a2f4-77ffff563aa5%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate