Hello again.
I tried this:

AsignacionItemFormset = formset_factory(AsignacionItemForm,
can_delete=True, extra=0)
initial_data = []
for item in initialdataquery:
    initial_data.append({...})
# Now I append an extra item with the defaul initial data
initial_data.append({'asignacion_id':1})
formset = AsignacionItemFormset(initial=initial_data)

I still get the 'required field' error for the forms.
What I want to do here is let the user use the extra form to append a
new item using some default values but that should be optional.


On Oct 14, 6:09 am, gearheart <[EMAIL PROTECTED]> wrote:
> hi
> form is being cleaned only if it's values are different from initial
> values, so debug.
> btw,
>  you can't do form.field['..'].initial = '..'
>  initial must be dictionary, not list
>
> V.
>
> On Oct 14, 12:34 am, Federico H <[EMAIL PROTECTED]> wrote:
>
> > Hi,
> > I'm using a formset with hidden fields in the forms and other required
> > fields. Those fields need to be initialized with some value. When I
> > try to validate the formset I get "required field" errors for those
> > other required fields. The formset apparently thinks that the
> > extraform is half filled (because of the initial data for the hidden
> > fields).
> > How can I avoid that behavior?
> > Let me give you an example (may not be completely right cause I'm
> > extracting the relevant parts of the original code):
>
> > class ItemForm(forms.Form):
> >     asignacion_id = forms.IntegerField(label="ID de la asignación",
> > required=True)
> >     gondola = forms.ModelChoiceField(Gondola.objects.all(),
> > required=True, label="Góndola")
> >     def clean_gondola(self)
> >          # Some code that uses asignacion_id
>
> > def myView(request):
> >     AsignacionItemFormset = formset_factory(ItemForm)
> >     formset = AsignacionItemFormset(request.POST, request.FILES)
> >     formset.is_valid() # Returns false with "required field" errors
> > for the extra form
> >     ...
> >     if not request.POST:
> >         formset = AsignacionItemFormset(initial=[{'asignacion_id':1,
> > 'gondola':gon_id}])
> >         for form in formset.forms:
> >             form.fields['asignacion_id'].initial = 1 # To make sure
> > every asignacion_id is initialized to 1 (even the extra ones)
>
> > I hope someone can help me with these.
--~--~---------~--~----~------------~-------~--~----~
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