jazzband / jazzband/django-floppyforms

Select widget outputs None value as string

Open
#185 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
836
Forks
150
PR merge metrics
No merged PRs in 30d

Description

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:
`No. of doors`

This is different to Django's native forms which render the first option as:
`No. of doors`

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?

Contributor guide

Open the contributing guide

Research direction

Reproduce the issue with the provided ChoiceField and compare floppyforms' Select widget output with Django's native widget. Trace the widget rendering path responsible for converting the null choice and verify that the rendered value and returned value match Django's empty-value behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
django, python
Domain
frontend, web-dev
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.