Tuesday, June 21, 2011

how to display form data with original values after validation failure?

In the case of editing a form, I want to display the original value of
a field prior to validation failure, as well as the validation
errors. This doesn't seem to work:

if fs.is_valid():
fs.save()
else:
# return original data - not default changed data
errors = fs._errors
q =
JosJeventsRegistration.objects.using('default').filter(user=user,
status='cart')
fs = RegistrationFormSet(queryset=q)
fs._errors = errors

Context:

For my UI on a class registration shopping cart, a user can edit the
number of guests. Some classes have limited availability for certain
roles - e.g. there may only be 2 spaces available, so the user can
only enter 2 guests (including themselves). The current error
messaging says "There are only x more spaces available for this
role." If the user already had 1 guest and then enters 4 guests, then
it's unclear how many spaces the user can enter to correct the error
unless they remembered the original value. I think it would be more
straight forward if the form reset to its original values and
displayed the error.

Any tips on how to best accomplish this would be greatly appreciated.

--
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 django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate