Wednesday, December 29, 2010

Question about custom form widgets and validation

Hi everyone,

I'm working on a custom form widget to input length values in feet,
inches and a fraction of an inch. So far, everything is working as
expected, except for validation.

It takes a value input as:
1' 10 1/2" and converts it into inches: 22.5, for storage in a
database.

My widget combines two text inputs and a select to create the decimal
value. So, I'm using a DecimalField and supplying my widget. However,
if I input a non-numeric value, I'm getting a ValueError in my
value_from_datadict method.

So, obviously I need a try/except in that method, but how do I go
about adding an error message to the field instead of raising a
runtime exception?

Once I get this finished, I'd like to add it to Django Snippets to
share.

Thanks,
Brandon

--
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.

No comments:

Post a Comment