jazzband / django-floppyforms

Full control of form rendering in the templates.
http://django-floppyforms.readthedocs.org/
Other
837 stars 148 forks source link

Select widget outputs None value as string #185

Open authcode opened 7 years ago

authcode commented 7 years ago

I have floppyforms ChoiceField rendering with a Select widget. The choices include a null value:

    NUM_DOORS_2 = 2
    NUM_DOORS_3 = 3
    NUM_DOORS_CHOICES = (
        (None, 'No. of doors'),
        (NUM_DOORS_2, 2),
        (NUM_DOORS_3, 3),
    )

    num_doors = forms.ChoiceField(NUM_DOORS_CHOICES, required=False)

When the select element renders the first option is: <option value="None" selected="selected">No. of doors</option>

This is different to Django's native forms which render the first option as: <option value="" selected="selected">No. of doors</option>

The value returned by the floppyforms select list is the unicode string "None". The value returned by Django's native select list widget is None type.

This difference is significant and has produced a number of bugs in my project. I have fixed it by overriding the select widget template and checking for the string "None", but the None type is apparently being coerced into a string by the floppyforms select widget.

Is this behaviour intentional?