iommirocks / iommi

Your first pick for a django power cord
http://iommi.rocks
BSD 3-Clause "New" or "Revised" License
688 stars 47 forks source link

CharField with choices non-required is_valid #462

Closed berycz closed 11 months ago

berycz commented 11 months ago

I have a CharField with choices, blank=True, null=False the select gets the first empty choice but if I leave it empty and submit, I get "not in available choices"

I'm not sure whether this should be in Field._validate where you check for self.parsed_data is not None or if it should be in choice_is_valid ?

berycz commented 11 months ago

or maybe to add

class Field:
    ...
    def is_empty(self):
        if self.parse_empty_string_as_none and self.parsed_data is None:
            return True
        elif not self.parse_empty_string_as_none and self.parsed_data == "":
            return True
        return False

which could be overriden for some specific fields?

yurkobb commented 11 months ago

This also seems to be a regression - it does not happen in 6.0.0, and appears first in 6.1.0.