python - Django Forms: No 'field errors' or 'non field errors'. But is_valid returns false -
views.py
form1 = form1(temp_arg=obj) form2 = form2() if request.method == 'post': print "submitting form" form1 = form1(request.post) form2 = form2(request.post) print form1.is_valid # prints false print form2.is_valid # prints true print form1.errors # prints none print form2.errors # prints none print form1.non_field_errors() # prints none print form2.non_field_errors() # prints none if form1.is_valid() , form2.is_valid(): print "form valid" # not executed #some code form.save , else: print "error!" # prints
forms.py
@parsleyfy class form1(modelform): def __init__(self, temp_arg, *args, **kwargs): temp_val = temp_arg super(form1, self).__init__(*args, **kwargs) self.fields['field1'] = forms.choicefield( choices=get_field_choices(temp_val)) class meta: model = model1
i have 2 forms. 1 form contains choice field need loaded dynamically. wrote function get_field_choices
, called __ init __
function of form. working until added temp_argument this. problem form dynamic loading function not getting validated. form.errors
, form.non_field_errors
returns nothing. unable trace wrong form.
instead of form1 = form1(request.post)
, used
form1 = form1(temp_arg=obj,data=request.post)
. , worked.
Comments
Post a Comment