Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Select widget outputs None value as string #185

Open
authcode opened this issue Mar 10, 2017 · 0 comments
Open

Select widget outputs None value as string #185

authcode opened this issue Mar 10, 2017 · 0 comments

Comments

@authcode
Copy link

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant