pub struct DateField<S, T> { /* private fields */ }Expand description
A date field bound to a CalendarDate or Option<CalendarDate> signal, with its label.
Where given, a description and an error message are tied to it.
It is an <input type="date"> with the ids, aria-describedby, and
aria-invalid of a TextField. The browser draws
its own date picker. min and
max take a CalendarDate, so a bound cannot be text.
use hypersig::{CalendarDate, Signals};
use hypersig_ui::DateField;
use serde::{Deserialize, Serialize};
#[derive(Signals, Serialize, Deserialize)]
struct Booking {
arrival: Option<CalendarDate>,
}
let arrival = DateField::new("Arrival", Booking::arrival())
.min(CalendarDate::new(2026, 1, 1))
.max(CalendarDate::new(2026, 12, 31));
let html = arrival.render().render();
assert!(html.contains(r#"type="date""#));
assert!(html.contains(r#"min="2026-01-01""#));
assert!(html.contains(r#"for="ui-arrival-input""#));Implementations§
Source§impl<S, T: Dated> DateField<S, T>
impl<S, T: Dated> DateField<S, T>
Sourcepub fn new(label: impl Into<String>, value: Sig<S, T>) -> Self
pub fn new(label: impl Into<String>, value: Sig<S, T>) -> Self
A date field labeled label, bound to value.
Sourcepub fn in_form<V: Validate>(
label: impl Into<String>,
form: Sig<S, Form<V>>,
field: Sig<V, T>,
) -> Self
pub fn in_form<V: Validate>( label: impl Into<String>, form: Sig<S, Form<V>>, field: Sig<V, T>, ) -> Self
A date field labeled label, bound to field of form.
It shows error of the form for field and marks the
field touched when the visitor leaves it, as
TextField::in_form does.
Sourcepub fn min(self, min: CalendarDate) -> Self
pub fn min(self, min: CalendarDate) -> Self
Sourcepub fn max(self, max: CalendarDate) -> Self
pub fn max(self, max: CalendarDate) -> Self
Sourcepub fn description(self, text: impl Into<String>) -> Self
pub fn description(self, text: impl Into<String>) -> Self
Adds a line under the field that aria-describedby points at.
Sourcepub fn error(self, message: impl IntoExpr<S, String>) -> Self
pub fn error(self, message: impl IntoExpr<S, String>) -> Self
Shows message under the field.
It marks the field invalid while message is not empty.
Sourcepub fn required(self) -> Self
pub fn required(self) -> Self
Marks the field required.
The label shows it with an asterisk that a screen reader skips.