Question

I guess my problem is clear from the title.

Basically i have a form with dynamic choice fields. And i create a blank option for the select field.

 choices = [('', '----------')]

Problem is if i submit blank option, form validates. I have django 1.5 installed, so even if in earlier version something like this worked, and validation exception was thrown, now it is not.

So the big question is , how and where should i validate something like this ?

I tried to ovveride Choicefield and it's validate method, but i still get the same result:

class DynamicChoiceField(forms.ChoiceField):
    # The only thing we need to override here is the validate function.
    def validate(self, value):
        if self.required and not value:
            raise ValidationError(self.error_messages['required'])

Andy ideas guys ?

Was it helpful?

Solution

YES , this is very clear for me. but what you get when you change the required =False . or try to use django force_insert =True in the model, i never used it , but try it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top