Hi gordy,
I worked around this issue by using:
class MyForm( forms.Form ):
.....
customer_id = forms.Field(widget=forms.HiddenInput,required=False)
def __init__( self, data=None, **kwargs ):
super( MyForm, self ).__init__( data, **kwargs )
self.fields['employee_id'] =
forms.ChoiceField(choices=[(c.id,c.description) for c in
ContactHistoryType.objects.all()])
works for me...
On 1/2/07, gordyt <[EMAIL PROTECTED]> wrote:
Howdy Folks,
Here is a fragment of a form definition:
class AddEditContactHistoryForm(forms.Form):
customer_id = forms.Field(widget=forms.HiddenInput,required=False)
contact_history_type_id = forms.ChoiceField(label='Contact Type',
choices=[(c.id,c.description) for c in
ContactHistoryType.objects.all()])
employee_id = forms.ChoiceField(label='Employee', required=False)
summary = forms.CharField(required=False)
date_opened = forms.DateField(initial=date.today())
Say I wanted to update the employee_id field at runtime. This little
fragment from the view seems to work, but I'm wondering if there is a
better (proper?) way:
edit_form = AddEditContactHistoryForm()
edit_form.fields['employee_id'].widget.choices = [('','Select')] +
[(c.id,"%s, %s (%s)" %
(c.person.last_name,c.person.first_name,c.title))
for c in employees]
edit_form.fields['employee_id'].choices =
edit_form.fields['employee_id'].widget.choices
The last line of that is required or else the form doesn't validate.
Thanks!
--gordy
>
--
Honza Kr l
E-Mail: [EMAIL PROTECTED]
ICQ#: 107471613
Phone: +420 606 678585
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Django
users" group.
To post to this group, send email to [email protected]
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
-~----------~----~----~----~------~----~------~--~---