On Mon, 2007-04-30 at 01:04 +0000, Mike Thompson wrote:
> Thanks Henrik -
> 
> I'm actually trying to pass initial data (a default date).  Right now,
> the widget defaults to 'January 1, 2007'... and renders HTML with
> 'selected' form attributes on that month, day and year.  I would like
> to pass, for example, '2007-04-15', to the render method of the
> SelectDateWidget and have the 'selected's appear next to April, 15 and
> 2007.  i can get this working in the python interpreter window, but
> not within a django template.  Thanks again for your suggestions.

For the future, you keep hinting that you have something that almost
does what you want or works in one case but not the other, but you
aren't showing any code. So it's a bit hard to correct what you're
attempting and sometimes it's easier for somebody to see how to modify
what you've already tried.

In any case, here's an example of constructing a form that will select
the initial date:
        
        class Example(Form):
            date = DateField(label='date', initial='2007-04-29', 
widget=extras.SelectDateWidget(years=range(2007, 2000, -1)))

If you create an instance of this form and render it, the initial value
is selected, as expected. The "initial" attribute is documented at the
top of newforms.field.Field.

You can also set it at a later point in time by just poking into the
"initial" attribute on the Field sub-classes. The attribute isn't used
or modified until render time.

Regards,
Malcolm


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to