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

FloatField use NumberInput by default #679

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/wtforms/fields/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -818,7 +818,7 @@ class FloatField(Field):
is ignored and will not be accepted as a value.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The documentation for this class needs to be updated

"""

widget = widgets.TextInput()
widget = widgets.NumberInput(step="any")

def __init__(self, label=None, validators=None, **kwargs):
super().__init__(label, validators, **kwargs)
Expand Down
6 changes: 4 additions & 2 deletions tests/fields/test_float.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ def test_float_field():
form = F(DummyPostData(a=["v"], b=["-15.0"]))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to test the "step" values association to the float input data. So a step of "any" is good with "1.234" but a step of "0.1" should not validate a "1.234" input.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for your input, it looks like this related to this issue #658.

assert form.a.data is None
assert form.a.raw_data == ["v"]
assert form.a() == """<input id="a" name="a" type="text" value="v">"""
assert form.a() == """<input id="a" name="a" step="any" type="number" value="v">"""
assert form.b.data == -15.0
assert form.b() == """<input id="b" name="b" type="text" value="-15.0">"""
assert (
form.b() == """<input id="b" name="b" step="any" type="number" value="-15.0">"""
)
assert not form.a.validate(form)
assert form.b.validate(form)
form = F(DummyPostData(a=[], b=[""]))
Expand Down