html_sys/forms/
input.rs

1/// The HTML `<input>` element
2///
3/// [MDN Documentation](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input)
4#[doc(alias = "input")]
5#[non_exhaustive]
6#[derive(Debug, Clone, PartialEq, Default)]
7pub struct Input {
8    pub data_map: crate::DataMap,
9    global_attrs: crate::GlobalAttributes,
10    /// Hint for expected file type in file upload controls
11    pub accept: std::option::Option<std::borrow::Cow<'static, str>>,
12    /// Replacement text for use when images are not available
13    pub alt: std::option::Option<std::borrow::Cow<'static, str>>,
14    /// Hint for form autofill feature
15    pub autocomplete: std::option::Option<std::borrow::Cow<'static, str>>,
16    /// Whether the control is checked
17    pub checked: std::option::Option<std::borrow::Cow<'static, str>>,
18    /// Name of form control to use for sending the element's directionality in form submission
19    pub dirname: std::option::Option<std::borrow::Cow<'static, str>>,
20    /// Whether the form control is disabled
21    pub disabled: std::option::Option<std::borrow::Cow<'static, str>>,
22    /// Associates the element with a form element
23    pub form: std::option::Option<std::borrow::Cow<'static, str>>,
24    /// URL to use for form submission
25    pub formaction: std::option::Option<std::borrow::Cow<'static, str>>,
26    /// Entry list encoding type to use for form submission
27    pub formenctype: std::option::Option<std::borrow::Cow<'static, str>>,
28    /// Variant to use for form submission
29    pub formmethod: std::option::Option<std::borrow::Cow<'static, str>>,
30    /// Bypass form control validation for form submission
31    pub formnovalidate: std::option::Option<std::borrow::Cow<'static, str>>,
32    /// Navigable for form submission
33    pub formtarget: std::option::Option<std::borrow::Cow<'static, str>>,
34    /// Vertical dimension
35    pub height: std::option::Option<std::borrow::Cow<'static, str>>,
36    /// List of autocomplete options
37    pub list: std::option::Option<std::borrow::Cow<'static, str>>,
38    /// Maximum value
39    pub max: std::option::Option<std::borrow::Cow<'static, str>>,
40    /// Maximum length of value
41    pub maxlength: std::option::Option<std::borrow::Cow<'static, str>>,
42    /// Minimum value
43    pub min: std::option::Option<std::borrow::Cow<'static, str>>,
44    /// Minimum length of value
45    pub minlength: std::option::Option<std::borrow::Cow<'static, str>>,
46    /// Whether to allow multiple values
47    pub multiple: std::option::Option<std::borrow::Cow<'static, str>>,
48    /// Name of the element to use for form submission and in the form.elements API
49    pub name: std::option::Option<std::borrow::Cow<'static, str>>,
50    /// Pattern to be matched by the form control's value
51    pub pattern: std::option::Option<std::borrow::Cow<'static, str>>,
52    /// User-visible label to be placed within the form control
53    pub placeholder: std::option::Option<std::borrow::Cow<'static, str>>,
54    /// Targets a popover element to toggle, show, or hide
55    pub popovertarget: std::option::Option<std::borrow::Cow<'static, str>>,
56    /// Indicates whether a targeted popover element is to be toggled, shown, or hidden
57    pub popovertargetaction: std::option::Option<std::borrow::Cow<'static, str>>,
58    /// Whether to allow the value to be edited by the user
59    pub readonly: std::option::Option<std::borrow::Cow<'static, str>>,
60    /// Whether the control is required for form submission
61    pub required: std::option::Option<std::borrow::Cow<'static, str>>,
62    /// Size of the control
63    pub size: std::option::Option<std::borrow::Cow<'static, str>>,
64    /// Address of the resource
65    pub src: std::option::Option<std::borrow::Cow<'static, str>>,
66    /// Granularity to be matched by the form control's value
67    pub step: std::option::Option<std::borrow::Cow<'static, str>>,
68    /// Type of form control
69    pub type_: std::option::Option<std::borrow::Cow<'static, str>>,
70    /// Value of the form control
71    pub value: std::option::Option<std::borrow::Cow<'static, str>>,
72    /// Horizontal dimension
73    pub width: std::option::Option<std::borrow::Cow<'static, str>>,
74    /// Describes the role(s) the current element plays in the context of the document.
75    pub role: std::option::Option<std::borrow::Cow<'static, str>>,
76    /// Identifies the currently active element when DOM focus is on a composite widget, combobox, textbox, group, or application.
77    pub aria_active_descendant_element: std::option::Option<
78        std::borrow::Cow<'static, str>,
79    >,
80    /// Indicates whether assistive technologies will present all, or only parts of, the changed region based on the change notifications defined by the aria-relevant attribute.
81    pub aria_atomic: bool,
82    /// Indicates whether inputting text could trigger display of one or more predictions of the user's intended value for a combobox, searchbox, or textbox and specifies how predictions would be presented if they were made.
83    pub aria_auto_complete: std::option::Option<std::borrow::Cow<'static, str>>,
84    /// Defines a string value that labels the current element, which is intended to be converted into Braille. See related aria-label.
85    pub aria_braille_label: std::option::Option<std::borrow::Cow<'static, str>>,
86    /// Defines a human-readable, author-localized abbreviated description for the role of an element, which is intended to be converted into Braille. See related aria-roledescription.
87    pub aria_braille_role_description: std::option::Option<
88        std::borrow::Cow<'static, str>,
89    >,
90    /// Indicates an element is being modified and that assistive technologies could wait until the modifications are complete before exposing them to the user.
91    pub aria_busy: bool,
92    /// Indicates the current "checked" state of checkboxes, radio buttons, and other widgets. See related aria-pressed and aria-selected.
93    pub aria_checked: std::option::Option<std::borrow::Cow<'static, str>>,
94    /// Defines an element's column index or position with respect to the total number of columns within a table, grid, or treegrid. See related aria-colindextext, aria-colcount, and aria-colspan.
95    pub aria_col_index: std::option::Option<i64>,
96    /// Defines a human readable text alternative of aria-colindex. See related aria-rowindextext.
97    pub aria_col_index_text: std::option::Option<std::borrow::Cow<'static, str>>,
98    /// Defines the number of columns spanned by a cell or gridcell within a table, grid, or treegrid. See related aria-colindex and aria-rowspan.
99    pub aria_col_span: std::option::Option<i64>,
100    /// Identifies the element (or elements) whose contents or presence are controlled by the current element. See related aria-owns.
101    pub aria_controls_elements: std::option::Option<std::borrow::Cow<'static, str>>,
102    /// Indicates the element that represents the current item within a container or set of related elements.
103    pub aria_current: std::option::Option<std::borrow::Cow<'static, str>>,
104    /// Identifies the element (or elements) that describes the object. See related aria-labelledby and aria-description.
105    pub aria_described_by_elements: std::option::Option<std::borrow::Cow<'static, str>>,
106    /// Defines a string value that describes or annotates the current element. See related aria-describedby.
107    pub aria_description: std::option::Option<std::borrow::Cow<'static, str>>,
108    /// Identifies the element (or elements) that provide additional information related to the object. See related aria-describedby.
109    pub aria_details_elements: std::option::Option<std::borrow::Cow<'static, str>>,
110    /// Indicates that the element is perceivable but disabled, so it is not editable or otherwise operable. See related aria-hidden and aria-readonly.
111    pub aria_disabled: bool,
112    /// [Deprecated in ARIA 1.1] Indicates what functions can be performed when a dragged object is released on the drop target.
113    pub aria_drop_effect: std::option::Option<std::borrow::Cow<'static, str>>,
114    /// Identifies the element (or elements) that provides an error message for an object. See related aria-invalid and aria-describedby.
115    pub aria_error_message_elements: std::option::Option<std::borrow::Cow<'static, str>>,
116    /// Indicates whether a grouping element owned or controlled by this element is expanded or collapsed.
117    pub aria_expanded: bool,
118    /// Identifies the next element (or elements) in an alternate reading order of content which, at the user's discretion, allows assistive technology to override the general default of reading in document source order.
119    pub aria_flow_to_elements: std::option::Option<std::borrow::Cow<'static, str>>,
120    /// [Deprecated in ARIA 1.1] Indicates an element's "grabbed" state in a drag-and-drop operation.
121    pub aria_grabbed: bool,
122    /// Indicates the availability and type of interactive popup element, such as menu or dialog, that can be triggered by an element.
123    pub aria_has_popup: std::option::Option<std::borrow::Cow<'static, str>>,
124    /// Indicates whether the element is exposed to an accessibility API. See related aria-disabled.
125    pub aria_hidden: bool,
126    /// Indicates the entered value does not conform to the format expected by the application. See related aria-errormessage.
127    pub aria_invalid: std::option::Option<std::borrow::Cow<'static, str>>,
128    /// Defines keyboard shortcuts that an author has implemented to activate or give focus to an element.
129    pub aria_key_shortcuts: std::option::Option<std::borrow::Cow<'static, str>>,
130    /// Defines a string value that labels the current element. See related aria-labelledby.
131    pub aria_label: std::option::Option<std::borrow::Cow<'static, str>>,
132    /// Identifies the element (or elements) that labels the current element. See related aria-label and aria-describedby.
133    pub aria_labelled_by_elements: std::option::Option<std::borrow::Cow<'static, str>>,
134    /// Defines the hierarchical level of an element within a structure.
135    pub aria_level: std::option::Option<i64>,
136    /// Indicates that an element will be updated, and describes the types of updates the user agents, assistive technologies, and user can expect from the live region.
137    pub aria_live: std::option::Option<std::borrow::Cow<'static, str>>,
138    /// Indicates whether a text box accepts multiple lines of input or only a single line.
139    pub aria_multi_line: bool,
140    /// Indicates whether the element's orientation is horizontal, vertical, or unknown/ambiguous.
141    pub aria_orientation: std::option::Option<std::borrow::Cow<'static, str>>,
142    /// Identifies an element (or elements) in order to define a visual, functional, or contextual parent/child relationship between DOM elements where the DOM hierarchy cannot be used to represent the relationship. See related aria-controls.
143    pub aria_owns_elements: std::option::Option<std::borrow::Cow<'static, str>>,
144    /// Defines a short hint (a word or short phrase) intended to aid the user with data entry when the control has no value. A hint could be a sample value or a brief description of the expected format.
145    pub aria_placeholder: std::option::Option<std::borrow::Cow<'static, str>>,
146    /// Defines an element's number or position in the current set of listitems or treeitems. Not required if all elements in the set are present in the DOM. See related aria-setsize.
147    pub aria_pos_in_set: std::option::Option<i64>,
148    /// Indicates the current "pressed" state of toggle buttons. See related aria-checked and aria-selected.
149    pub aria_pressed: std::option::Option<std::borrow::Cow<'static, str>>,
150    ///  Indicates that the element is not editable, but is otherwise operable. See related aria-disabled.
151    pub aria_read_only: bool,
152    /// Indicates what notifications the user agent will trigger when the accessibility tree within a live region is modified. See related aria-atomic.
153    pub aria_relevant: std::option::Option<std::borrow::Cow<'static, str>>,
154    /// Indicates that user input is required on the element before a form can be submitted.
155    pub aria_required: bool,
156    /// Defines a human-readable, author-localized description for the role of an element.
157    pub aria_role_description: std::option::Option<std::borrow::Cow<'static, str>>,
158    /// Defines an element's row index or position with respect to the total number of rows within a table, grid, or treegrid. See related aria-rowindextext, aria-rowcount, and aria-rowspan.
159    pub aria_row_index: std::option::Option<i64>,
160    /// Defines a human readable text alternative of aria-rowindex. See related aria-colindextext.
161    pub aria_row_index_text: std::option::Option<std::borrow::Cow<'static, str>>,
162    /// Defines the number of rows spanned by a cell or gridcell within a table, grid, or treegrid. See related aria-rowindex and aria-colspan.
163    pub aria_row_span: std::option::Option<i64>,
164    /// Indicates the current "selected" state of various widgets. See related aria-checked and aria-pressed.
165    pub aria_selected: bool,
166    /// Defines the number of items in the current set of listitems or treeitems. Not required if all elements in the set are present in the DOM. See related aria-posinset.
167    pub aria_set_size: std::option::Option<i64>,
168    /// Defines the maximum allowed value for a range widget.
169    pub aria_value_max: std::option::Option<f64>,
170    /// Defines the minimum allowed value for a range widget.
171    pub aria_value_min: std::option::Option<f64>,
172    /// Defines the current value for a range widget. See related aria-valuetext.
173    pub aria_value_now: std::option::Option<f64>,
174    /// Defines the human readable text alternative of aria-valuenow for a range widget.
175    pub aria_value_text: std::option::Option<std::borrow::Cow<'static, str>>,
176}
177impl crate::RenderElement for Input {
178    fn write_opening_tag<W: std::fmt::Write>(&self, writer: &mut W) -> std::fmt::Result {
179        write!(writer, "<input")?;
180        if let Some(field) = self.accept.as_ref() {
181            write!(writer, r#" accept="{field}""#)?;
182        }
183        if let Some(field) = self.alt.as_ref() {
184            write!(writer, r#" alt="{field}""#)?;
185        }
186        if let Some(field) = self.autocomplete.as_ref() {
187            write!(writer, r#" autocomplete="{field}""#)?;
188        }
189        if let Some(field) = self.checked.as_ref() {
190            write!(writer, r#" checked="{field}""#)?;
191        }
192        if let Some(field) = self.dirname.as_ref() {
193            write!(writer, r#" dirname="{field}""#)?;
194        }
195        if let Some(field) = self.disabled.as_ref() {
196            write!(writer, r#" disabled="{field}""#)?;
197        }
198        if let Some(field) = self.form.as_ref() {
199            write!(writer, r#" form="{field}""#)?;
200        }
201        if let Some(field) = self.formaction.as_ref() {
202            write!(writer, r#" formaction="{field}""#)?;
203        }
204        if let Some(field) = self.formenctype.as_ref() {
205            write!(writer, r#" formenctype="{field}""#)?;
206        }
207        if let Some(field) = self.formmethod.as_ref() {
208            write!(writer, r#" formmethod="{field}""#)?;
209        }
210        if let Some(field) = self.formnovalidate.as_ref() {
211            write!(writer, r#" formnovalidate="{field}""#)?;
212        }
213        if let Some(field) = self.formtarget.as_ref() {
214            write!(writer, r#" formtarget="{field}""#)?;
215        }
216        if let Some(field) = self.height.as_ref() {
217            write!(writer, r#" height="{field}""#)?;
218        }
219        if let Some(field) = self.list.as_ref() {
220            write!(writer, r#" list="{field}""#)?;
221        }
222        if let Some(field) = self.max.as_ref() {
223            write!(writer, r#" max="{field}""#)?;
224        }
225        if let Some(field) = self.maxlength.as_ref() {
226            write!(writer, r#" maxlength="{field}""#)?;
227        }
228        if let Some(field) = self.min.as_ref() {
229            write!(writer, r#" min="{field}""#)?;
230        }
231        if let Some(field) = self.minlength.as_ref() {
232            write!(writer, r#" minlength="{field}""#)?;
233        }
234        if let Some(field) = self.multiple.as_ref() {
235            write!(writer, r#" multiple="{field}""#)?;
236        }
237        if let Some(field) = self.name.as_ref() {
238            write!(writer, r#" name="{field}""#)?;
239        }
240        if let Some(field) = self.pattern.as_ref() {
241            write!(writer, r#" pattern="{field}""#)?;
242        }
243        if let Some(field) = self.placeholder.as_ref() {
244            write!(writer, r#" placeholder="{field}""#)?;
245        }
246        if let Some(field) = self.popovertarget.as_ref() {
247            write!(writer, r#" popovertarget="{field}""#)?;
248        }
249        if let Some(field) = self.popovertargetaction.as_ref() {
250            write!(writer, r#" popovertargetaction="{field}""#)?;
251        }
252        if let Some(field) = self.readonly.as_ref() {
253            write!(writer, r#" readonly="{field}""#)?;
254        }
255        if let Some(field) = self.required.as_ref() {
256            write!(writer, r#" required="{field}""#)?;
257        }
258        if let Some(field) = self.size.as_ref() {
259            write!(writer, r#" size="{field}""#)?;
260        }
261        if let Some(field) = self.src.as_ref() {
262            write!(writer, r#" src="{field}""#)?;
263        }
264        if let Some(field) = self.step.as_ref() {
265            write!(writer, r#" step="{field}""#)?;
266        }
267        if let Some(field) = self.type_.as_ref() {
268            write!(writer, r#" type="{field}""#)?;
269        }
270        if let Some(field) = self.value.as_ref() {
271            write!(writer, r#" value="{field}""#)?;
272        }
273        if let Some(field) = self.width.as_ref() {
274            write!(writer, r#" width="{field}""#)?;
275        }
276        if let Some(field) = self.role.as_ref() {
277            write!(writer, r#" role="{field}""#)?;
278        }
279        if let Some(field) = self.aria_active_descendant_element.as_ref() {
280            write!(writer, r#" aria-activedescendant="{field}""#)?;
281        }
282        if self.aria_atomic {
283            write!(writer, r#" aria-atomic"#)?;
284        }
285        if let Some(field) = self.aria_auto_complete.as_ref() {
286            write!(writer, r#" aria-autocomplete="{field}""#)?;
287        }
288        if let Some(field) = self.aria_braille_label.as_ref() {
289            write!(writer, r#" aria-braillelabel="{field}""#)?;
290        }
291        if let Some(field) = self.aria_braille_role_description.as_ref() {
292            write!(writer, r#" aria-brailleroledescription="{field}""#)?;
293        }
294        if self.aria_busy {
295            write!(writer, r#" aria-busy"#)?;
296        }
297        if let Some(field) = self.aria_checked.as_ref() {
298            write!(writer, r#" aria-checked="{field}""#)?;
299        }
300        if let Some(field) = self.aria_col_index.as_ref() {
301            write!(writer, r#" aria-colindex="{field}""#)?;
302        }
303        if let Some(field) = self.aria_col_index_text.as_ref() {
304            write!(writer, r#" aria-colindextext="{field}""#)?;
305        }
306        if let Some(field) = self.aria_col_span.as_ref() {
307            write!(writer, r#" aria-colspan="{field}""#)?;
308        }
309        if let Some(field) = self.aria_controls_elements.as_ref() {
310            write!(writer, r#" aria-controls="{field}""#)?;
311        }
312        if let Some(field) = self.aria_current.as_ref() {
313            write!(writer, r#" aria-current="{field}""#)?;
314        }
315        if let Some(field) = self.aria_described_by_elements.as_ref() {
316            write!(writer, r#" aria-describedby="{field}""#)?;
317        }
318        if let Some(field) = self.aria_description.as_ref() {
319            write!(writer, r#" aria-description="{field}""#)?;
320        }
321        if let Some(field) = self.aria_details_elements.as_ref() {
322            write!(writer, r#" aria-details="{field}""#)?;
323        }
324        if self.aria_disabled {
325            write!(writer, r#" aria-disabled"#)?;
326        }
327        if let Some(field) = self.aria_drop_effect.as_ref() {
328            write!(writer, r#" aria-dropeffect="{field}""#)?;
329        }
330        if let Some(field) = self.aria_error_message_elements.as_ref() {
331            write!(writer, r#" aria-errormessage="{field}""#)?;
332        }
333        if self.aria_expanded {
334            write!(writer, r#" aria-expanded"#)?;
335        }
336        if let Some(field) = self.aria_flow_to_elements.as_ref() {
337            write!(writer, r#" aria-flowto="{field}""#)?;
338        }
339        if self.aria_grabbed {
340            write!(writer, r#" aria-grabbed"#)?;
341        }
342        if let Some(field) = self.aria_has_popup.as_ref() {
343            write!(writer, r#" aria-haspopup="{field}""#)?;
344        }
345        if self.aria_hidden {
346            write!(writer, r#" aria-hidden"#)?;
347        }
348        if let Some(field) = self.aria_invalid.as_ref() {
349            write!(writer, r#" aria-invalid="{field}""#)?;
350        }
351        if let Some(field) = self.aria_key_shortcuts.as_ref() {
352            write!(writer, r#" aria-keyshortcuts="{field}""#)?;
353        }
354        if let Some(field) = self.aria_label.as_ref() {
355            write!(writer, r#" aria-label="{field}""#)?;
356        }
357        if let Some(field) = self.aria_labelled_by_elements.as_ref() {
358            write!(writer, r#" aria-labelledby="{field}""#)?;
359        }
360        if let Some(field) = self.aria_level.as_ref() {
361            write!(writer, r#" aria-level="{field}""#)?;
362        }
363        if let Some(field) = self.aria_live.as_ref() {
364            write!(writer, r#" aria-live="{field}""#)?;
365        }
366        if self.aria_multi_line {
367            write!(writer, r#" aria-multiline"#)?;
368        }
369        if let Some(field) = self.aria_orientation.as_ref() {
370            write!(writer, r#" aria-orientation="{field}""#)?;
371        }
372        if let Some(field) = self.aria_owns_elements.as_ref() {
373            write!(writer, r#" aria-owns="{field}""#)?;
374        }
375        if let Some(field) = self.aria_placeholder.as_ref() {
376            write!(writer, r#" aria-placeholder="{field}""#)?;
377        }
378        if let Some(field) = self.aria_pos_in_set.as_ref() {
379            write!(writer, r#" aria-posinset="{field}""#)?;
380        }
381        if let Some(field) = self.aria_pressed.as_ref() {
382            write!(writer, r#" aria-pressed="{field}""#)?;
383        }
384        if self.aria_read_only {
385            write!(writer, r#" aria-readonly"#)?;
386        }
387        if let Some(field) = self.aria_relevant.as_ref() {
388            write!(writer, r#" aria-relevant="{field}""#)?;
389        }
390        if self.aria_required {
391            write!(writer, r#" aria-required"#)?;
392        }
393        if let Some(field) = self.aria_role_description.as_ref() {
394            write!(writer, r#" aria-roledescription="{field}""#)?;
395        }
396        if let Some(field) = self.aria_row_index.as_ref() {
397            write!(writer, r#" aria-rowindex="{field}""#)?;
398        }
399        if let Some(field) = self.aria_row_index_text.as_ref() {
400            write!(writer, r#" aria-rowindextext="{field}""#)?;
401        }
402        if let Some(field) = self.aria_row_span.as_ref() {
403            write!(writer, r#" aria-rowspan="{field}""#)?;
404        }
405        if self.aria_selected {
406            write!(writer, r#" aria-selected"#)?;
407        }
408        if let Some(field) = self.aria_set_size.as_ref() {
409            write!(writer, r#" aria-setsize="{field}""#)?;
410        }
411        if let Some(field) = self.aria_value_max.as_ref() {
412            write!(writer, r#" aria-valuemax="{field}""#)?;
413        }
414        if let Some(field) = self.aria_value_min.as_ref() {
415            write!(writer, r#" aria-valuemin="{field}""#)?;
416        }
417        if let Some(field) = self.aria_value_now.as_ref() {
418            write!(writer, r#" aria-valuenow="{field}""#)?;
419        }
420        if let Some(field) = self.aria_value_text.as_ref() {
421            write!(writer, r#" aria-valuetext="{field}""#)?;
422        }
423        write!(writer, "{}", self.global_attrs)?;
424        write!(writer, "{}", self.data_map)?;
425        write!(writer, ">")?;
426        Ok(())
427    }
428    #[allow(unused_variables)]
429    fn write_closing_tag<W: std::fmt::Write>(&self, writer: &mut W) -> std::fmt::Result {
430        Ok(())
431    }
432}
433impl std::fmt::Display for Input {
434    fn fmt(&self, writer: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
435        use crate::RenderElement;
436        self.write_opening_tag(writer)?;
437        self.write_closing_tag(writer)?;
438        Ok(())
439    }
440}
441impl std::ops::Deref for Input {
442    type Target = crate::GlobalAttributes;
443    fn deref(&self) -> &Self::Target {
444        &self.global_attrs
445    }
446}
447impl std::ops::DerefMut for Input {
448    fn deref_mut(&mut self) -> &mut Self::Target {
449        &mut self.global_attrs
450    }
451}