Skip to content

Commit 61fd60c

Browse files
committed
Form.autocomplete is now an enum attribute
1 parent 04732d3 commit 61fd60c

File tree

5 files changed

+21
-8
lines changed

5 files changed

+21
-8
lines changed

NEWS.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
# News in version 2.0.0
22

3+
## Incompatible Changes
4+
5+
* Drop support for Python 2.7 and 3.4.
6+
37
## API Additions
48

59
* Add `Video` element.
610
* Add `Button.disabled`.
711
* Add `autocomplete` attribute to `Input`, `TextArea`, `Select`, and `Form`.
812
* Add `enum_attribute`.
913

10-
## Incompatible Changes
11-
12-
* Drop support for Python 2.7 and 3.4.
13-
1414
# News in version 1.2.2
1515

1616
## API Additions

htmlgen/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
)
2626
from .element import ElementBase, Element, VoidElement, is_element
2727
from .form import (
28+
Autocomplete,
2829
Form,
2930
Input,
3031
TextInput,

htmlgen/form.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import datetime
22
import re
3+
from enum import Enum
34

45
from htmlgen.attribute import (
56
html_attribute,
67
boolean_html_attribute,
78
int_html_attribute,
89
float_html_attribute,
910
time_html_attribute,
10-
list_html_attribute,
11+
list_html_attribute, enum_attribute,
1112
)
1213
from htmlgen.block import Division
1314
from htmlgen.element import Element, VoidElement, is_element
@@ -18,6 +19,11 @@
1819
_ENC_TYPE_MULTI_PART = "multipart/form-data"
1920

2021

22+
class Autocomplete(Enum):
23+
OFF = "off"
24+
ON = "on"
25+
26+
2127
class Form(Element):
2228
"""An HTML <form> element.
2329
@@ -42,7 +48,7 @@ def __init__(self, method="GET", url=""):
4248
url = html_attribute("action", default="")
4349
target = html_attribute("target", "_self")
4450
encryption_type = html_attribute("enctype", _ENC_TYPE_URL_ENCODED)
45-
autocomplete = html_attribute("autocomplete")
51+
autocomplete = enum_attribute("autocomplete", Autocomplete)
4652

4753
def set_blank_target(self):
4854
self.target = "_blank"

htmlgen/form.pyi

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
import datetime
2+
from enum import Enum
23
from typing import List, Union, Optional
34

45
from htmlgen.element import Element, VoidElement
56
from htmlgen.generator import Generator
67

8+
class Autocomplete(Enum):
9+
OFF: str
10+
ON: str
11+
712
class Form(Element):
813
method: str
914
url: str

test_htmlgen/form.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
Option,
3232
Label,
3333
)
34+
from htmlgen.form import Autocomplete
3435

3536

3637
class FormTest(TestCase):
@@ -47,10 +48,10 @@ def test_implicit_arguments(self):
4748

4849
def test_arguments(self):
4950
form = Form("PUT", "/test")
50-
form.autocomplete = "username"
51+
form.autocomplete = Autocomplete.OFF
5152
assert_equal(
5253
[
53-
b'<form action="/test" autocomplete="username" method="PUT">',
54+
b'<form action="/test" autocomplete="off" method="PUT">',
5455
b"</form>",
5556
],
5657
list(iter(form)),

0 commit comments

Comments
 (0)