Skip to content

Select widget outputs None value as string #185

@authcode

Description

@authcode

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions