Thursday, January 29, 2015

Re: formset - how to set a from error from formset.clean?

Following up - this did the trick. Thanks for the pointer.
R.

On Mon, Jan 19, 2015 at 10:40 AM, Richard Brockie <richard@ontheday.net> wrote:
Thank you - that looks like what I am looking for! I don't know how I missed that.

I'm on 1.6 right now - another reason to move to 1.7 :)

R.

On Mon, Jan 19, 2015 at 9:16 AM, Collin Anderson <cmawebsite@gmail.com> wrote:
Hi,

You might be able to do something like:

self.forms[3].add_error('field_name', 'error message')


Collin

On Saturday, January 17, 2015 at 10:46:27 PM UTC-5, Richard Brockie wrote:
Hi everyone,

In a formset I can use the .clean() method to validate data across the formset. The formset.clean() method is run after all the form.clean() methods - this makes sense. Raising a formset ValidationError alerts the user to the problem with formset.non_form_errors.

I would like to also set an error condition on one of more of the individual forms as a result of this formset validation failure to help identify the location of the problems (my formsets can be quite long and this will help guide the eye). I've spent quite a lot of time looking for such an example with no success. Is there a way I can do this?

Here's some pseudo-code to outline what I want to do:

call MyFormSet(BaseFormSet):
   
def clean(self):
       
super(MyFormSet, self).clean()

       
# validation code goes here...

       
if some_validation_error:
           
raise ValidationError(...)    # creates the formset error message

            create_error_in_identified_forms
(somehow)    # <<<< I want to know how to do this bit

Thanks & best wishes!
R.

--
You received this message because you are subscribed to a topic in the Google Groups "Django users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/django-users/Ysef5zCb7Gc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to django-users+unsubscribe@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/ac19922b-a623-4083-9b86-e1ab4bf5892d%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
    R.

Richard Brockie

Real-time bicycle race results - www.ontheday.net



--
    R.

Richard Brockie

Real-time bicycle race results - www.ontheday.net

--
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+unsubscribe@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/CAKv-vOUsG24HBqHJp1kEF1HfMMhHq_gXHqxh9pLC-QmKCCkFkg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment