Hi Bill,

No luck:( I moved the `if any(self.errors):` to the bottom of the clean 
function and no change....

Thank you (again!) for your help,
Stephani

On Monday, April 6, 2015 at 12:12:58 PM UTC-4, Bill Blanchard wrote:
>
> Hi Stephanie,
> It looks like you're not returning anything when you hit an error.  Try:
>
> ...
> def clean(self):
>     if any(self.errors):
>         return self.errors
> ...
>
> On Mon, Apr 6, 2015 at 12:00 PM, Stephanie Socias <steph...@gmail.com 
> <javascript:>> wrote:
>
>> I implement a custom clean method to validate my formset. I know there 
>> are error as I can print them to the console but these non_form_errors() 
>> are never rendered in my template. How can I render them? 
>>
>> template.html:
>>
>> <form action="{% url 'databank:register' %}" method="post" 
>> enctype="multipart/form-data">
>>   {% csrf_token %}
>>
>>   <div class="container">
>>     <div class="row" style="margin-top: 30px"> 
>>       <div class="col-md-10 col-md-offset-1">
>>         {{ dataset_form.media }}
>>         {% crispy dataset_form %}
>>           <div class="authorFormset">
>>             {% for form in formset %}
>>               {% crispy form helper %}
>>             {% endfor %}    
>>           </div>
>>         {% crispy terms_form %}
>>       </div>
>>     </div>
>>   </div>
>>
>>   <div class="container">
>>     <div class="row">
>>       <div class="col-md-10 col-md-offset-1">
>>         <input type="submit" class="btn btn-lg btn-success" value="Submit">
>>       </div>
>>     </div>
>> </div>
>> {{ formset.management_form }}
>>
>> forms.py:
>>
>> class BaseAuthorFormset(BaseFormSet):
>>     def clean(self):   
>>         if any(self.errors):
>>             return
>>         roles = []
>>         for form in self.forms:
>>             contributor_role = form.cleaned_data['role']
>>             for x in contributor_role:
>>                 if (x == "Depositor") and (x in roles):
>>                     raise forms.ValidationError("Only one Contributor may be 
>> marked Depositor.")
>>                 roles.append(x)
>>             if "Depositor" not in roles:
>>                 raise forms.ValidationError("You must designate one 
>> Contributor as Depositor.")
>>
>>     def __init__(self, *args, **kwargs):
>>         super(BaseAuthorFormset, self).__init__(*args, **kwargs)
>>         for form in self.forms:
>>             form.empty_permitted = False
>>
>> class AuthorForm(forms.Form):
>>
>>     first_name = forms.CharField(
>>         max_length=96,
>>         required=True,
>>     )
>>
>>     middle_initial = forms.CharField(
>>         max_length=96,
>>         required=False,
>>     )
>>
>>     last_name = forms.CharField(
>>     max_length = 96,
>>     required = True,
>>     )
>>
>>  -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to django-users...@googlegroups.com <javascript:>.
>> To post to this group, send email to django...@googlegroups.com 
>> <javascript:>.
>> Visit this group at http://groups.google.com/group/django-users.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/392e7ff3-571f-4a52-b867-cbb3fe5b9c3f%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/django-users/392e7ff3-571f-4a52-b867-cbb3fe5b9c3f%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/1b8d7202-9588-4173-a86e-5e94ed69cf46%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to