pub struct NumberField<S, T> { /* private fields */ }Expand description
A number field bound to an i32 or f64 signal, with its label and,
where given, a description and an error message tied to it.
It is an <input type="number"> with the ids, aria-describedby, and
aria-invalid of a TextField. min, max, and
step take the field’s own type, so a bound cannot be text. A field
whose min is 0 or more asks for a keyboard of digits, which on a phone
has no minus sign. An f64 field without a step takes any decimal.
use hypersig::Signals;
use hypersig_ui::NumberField;
use serde::{Deserialize, Serialize};
#[derive(Signals, Serialize, Deserialize)]
struct Cart {
quantity: i32,
}
let quantity = NumberField::new("Quantity", Cart::quantity()).min(1).max(10);
let html = quantity.render().render();
assert!(html.contains(r#"type="number""#));
assert!(html.contains(r#"min="1""#));
assert!(html.contains(r#"inputmode="numeric""#));
assert!(html.contains(r#"for="ui-quantity-input""#));Implementations§
Source§impl<S, T: Numeric> NumberField<S, T>
impl<S, T: Numeric> NumberField<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 number 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 number 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: T) -> Self
pub fn min(self, min: T) -> Self
Sets the lowest value the browser accepts.
§Panics
Panics if min is above a maximum set before, or is not a number.
Sourcepub fn max(self, max: T) -> Self
pub fn max(self, max: T) -> Self
Sets the highest value the browser accepts.
§Panics
Panics if max is below a minimum set before, or is not a number.
Sourcepub fn step(self, step: T) -> Self
pub fn step(self, step: T) -> Self
Sets how far the arrow keys move the value, and which values the browser accepts: the minimum plus a whole number of steps.
§Panics
Panics if step is not above zero.
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 and marks the field invalid while
message is not empty.
Sourcepub fn required(self) -> Self
pub fn required(self) -> Self
Marks the field required, which the label shows with an asterisk
that a screen reader skips.