• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 735
  • Last Modified:

Django Form field validation error?

I created a form with the farbtastic color picker widget field.

After submitting the form, form field should validate that the color entered is a
valid 6-character hex encoding of a color.
But it not works.
How can I Fix this,

My code url is http://synergy.webfactional.com/widgets

forms.py
views.py
widgets.py
0
chaitanya_daphal
Asked:
chaitanya_daphal
1 Solution
 
XorceRCommented:
Your form code is invalid, you should not modify the is_valid() method of the form. Form validation should be done in the clean() method and clean_fieldname methods. Please check out the documentation on Django form validation: http://docs.djangoproject.com/en/1.1/ref/forms/validation/

In you example it should be something like this:
class ColorSelection(forms.Form):
  color = forms.CharField(max_length=100, widget=ColorPickerWidget)
  
  def clean_color(self):
    color = self.cleaned_data['color']
    
    if not color:
      raise forms.ValidationError("Please enter the color name!")

    if not rs.search(color):
      raise forms.ValidationError("Invalid color name!")
    
    return color

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now