Generic input. Type attribute must be specified when called directly. See also: Currently only types which can be written inside one ` ` tag are supported. - For checkbox, please use `Checkbox` class for bette
| 148 | |
| 149 | |
| 150 | class Input: |
| 151 | """Generic input. Type attribute must be specified when called directly. |
| 152 | |
| 153 | See also: <https://www.w3.org/TR/html52/sec-forms.html#the-input-element> |
| 154 | |
| 155 | Currently only types which can be written inside one `<input />` tag are |
| 156 | supported. |
| 157 | |
| 158 | - For checkbox, please use `Checkbox` class for better control. |
| 159 | - For radiobox, please use `Radio` class for better control. |
| 160 | |
| 161 | >>> Input(name='foo', type='email', value="user@domain.com").render() |
| 162 | u'<input id="foo" name="foo" type="email" value="user@domain.com"/>' |
| 163 | >>> Input(name='foo', type='number', value="bar").render() |
| 164 | u'<input id="foo" name="foo" type="number" value="bar"/>' |
| 165 | >>> Input(name='num', type="number", min='0', max='10', step='2', value='5').render() |
| 166 | u'<input id="num" max="10" min="0" name="num" step="2" type="number" value="5"/>' |
| 167 | >>> Input(name='foo', type="tel", value='55512345').render() |
| 168 | u'<input id="foo" name="foo" type="tel" value="55512345"/>' |
| 169 | >>> Input(name='search', type="search", value='Search').render() |
| 170 | u'<input id="search" name="search" type="search" value="Search"/>' |
| 171 | >>> Input(name='search', type="search", value='Search', required='required', pattern='[a-z0-9]{2,30}', placeholder='Search...').render() |
| 172 | u'<input id="search" name="search" pattern="[a-z0-9]{2,30}" placeholder="Search..." required="required" type="search" value="Search"/>' |
| 173 | >>> Input(name='url', type="url", value='url').render() |
| 174 | u'<input id="url" name="url" type="url" value="url"/>' |
| 175 | >>> Input(name='range', type="range", min='0', max='10', step='2', value='5').render() |
| 176 | u'<input id="range" max="10" min="0" name="range" step="2" type="range" value="5"/>' |
| 177 | >>> Input(name='color', type="color").render() |
| 178 | u'<input id="color" name="color" type="color"/>' |
| 179 | >>> Input(name='f', type="file", accept=".doc,.docx,.xml").render() |
| 180 | u'<input accept=".doc,.docx,.xml" id="f" name="f" type="file"/>' |
| 181 | """ |
| 182 | |
| 183 | def __init__(self, name, *validators, **attrs): |
| 184 | self.name = name |
| 185 | self.validators = validators |
| 186 | self.attrs = attrs = AttributeList(attrs) |
| 187 | |
| 188 | self.type = attrs.pop("type", None) |
| 189 | self.description = attrs.pop("description", name) |
| 190 | self.value = attrs.pop("value", None) |
| 191 | self.pre = attrs.pop("pre", "") |
| 192 | self.post = attrs.pop("post", "") |
| 193 | self.note = None |
| 194 | |
| 195 | self.id = attrs.setdefault("id", self.get_default_id()) |
| 196 | |
| 197 | if "class_" in attrs: |
| 198 | attrs["class"] = attrs["class_"] |
| 199 | del attrs["class_"] |
| 200 | |
| 201 | def is_hidden(self): |
| 202 | return False |
| 203 | |
| 204 | def get_type(self): |
| 205 | if self.type is not None: |
| 206 | return self.type |
| 207 | else: |
no outgoing calls