I figured out the puzzle: self.fields['state'] = forms.CharField(required=False, widget=forms.HiddenInput(), initial=self.instance.state)
Still open to feedback since I'm new to Django. On Jul 2, 11:19 am, Huuuze <[EMAIL PROTECTED]> wrote: > I use the following code to disable a ModelForm field in a custom > __init__: > > self.fields['state'] = > USStateField(widget=widgets.Select({'class':'disabled', 'disabled':'', > 'tabindex':'-1',}, choices=STATE_CHOICES), required=False) > > Unfortunately, this presents a problem. When I post the form with a > "disabled" Select field, the form is no longer valid since it expects > a value associated with State. Under non-Django conditions, I'd add a > hidden field that contains the value of the Select field and give it > the same name as the Select field. However, I'm having trouble > figuring out how to retrieve the value of the Select field to place > into a InputHidden field. This is operating under the assumption that > there isn't a better way to do this. :) > > For the sake of argument, here is my ModelForm: > > class BookForm(forms.ModelForm): > class Meta: > model = Book > > def __init__(self, *args, **kwargs): > super(BookForm, self).__init__(*args, **kwargs) > ... some other stuff happens here .... > self.fields['state'] = > USStateField(widget=widgets.Select({'class':'disabled', 'disabled':'', > 'tabindex':'-1',}, choices=STATE_CHOICES), required=False) --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---