Skip to main content

DateField

Struct DateField 

Source
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>

Source

pub fn new(label: impl Into<String>, value: Sig<S, T>) -> Self

A date field labeled label, bound to value.

Source

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.

Source

pub fn min(self, min: CalendarDate) -> Self

Sets the earliest date the browser accepts.

§Panics

Panics if min is after a maximum set before.

Source

pub fn max(self, max: CalendarDate) -> Self

Sets the latest date the browser accepts.

§Panics

Panics if max is before a minimum set before.

Source

pub fn description(self, text: impl Into<String>) -> Self

Adds a line under the field that aria-describedby points at.

Source

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.

Source

pub fn required(self) -> Self

Marks the field required.

The label shows it with an asterisk that a screen reader skips.

Source

pub fn disabled(self, when: impl IntoExpr<S, bool>) -> Self

Disables the field while when is true.

Source

pub fn render(self) -> El<S>

The label, the field, the description, and the error, in a <div>.

Trait Implementations§

Source§

impl<S: Debug, T: Debug> Debug for DateField<S, T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<S, T: Dated> From<DateField<S, T>> for El<S>

Source§

fn from(field: DateField<S, T>) -> Self

Converts to this type from the input type.
Source§

impl<S, T: Dated> From<DateField<S, T>> for Node<S>

Source§

fn from(field: DateField<S, T>) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl<S, T> Freeze for DateField<S, T>

§

impl<S, T> RefUnwindSafe for DateField<S, T>

§

impl<S, T> Send for DateField<S, T>

§

impl<S, T> Sync for DateField<S, T>

§

impl<S, T> Unpin for DateField<S, T>

§

impl<S, T> UnsafeUnpin for DateField<S, T>

§

impl<S, T> UnwindSafe for DateField<S, T>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<S, N> IntoNode<S> for N
where N: Into<Node<S>>,

Source§

fn into_node(self) -> Node<S>

Converts self into a node.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more