Skip to main content

checkbox_in_form

Function checkbox_in_form 

Source
pub fn checkbox_in_form<S, T: Validate>(
    text: impl Into<String>,
    form: Sig<S, Form<T>>,
    field: Sig<T, bool>,
) -> El<S>
Expand description

A checkbox labeled text, bound to field of form.

It is checkbox with the form’s error for field under it, tied to the input by aria-describedby and aria-invalid, and it marks the field touched when the visitor leaves the checkbox.

use hypersig::{Form, Rules, Sig, Signals, Validate};
use hypersig_ui::checkbox_in_form;
use serde::{Deserialize, Serialize};

#[derive(Signals, Serialize, Deserialize, Clone)]
struct Signup {
    terms: bool,
}

impl Validate for Signup {
    fn rules<S>(form: Sig<S, Self>, rules: &mut Rules<S, Self>) {
        rules.check(Signup::terms(), form.at(Signup::terms()), "Accept the terms.");
    }
}

#[derive(Signals, Serialize, Deserialize)]
struct Join {
    signup: Form<Signup>,
}

let terms = checkbox_in_form("I accept the terms", Join::signup(), Signup::terms());
assert!(terms.render().contains(r#"aria-describedby="ui-signup-value-terms-error""#));