Trait BindAttribute

pub trait BindAttribute<Key, Sig, T>
where Key: AttributeKey, Sig: IntoSplitSignal<Value = T>, T: FromEventTarget + AttributeValue + 'static,
{ type Output; // Required method fn bind(self, key: Key, signal: Sig) -> Self::Output; }
Expand description

Adds a two-way binding to the element, which adds an attribute and an event listener to the element when the element is created or hydrated.

Required Associated Types§

type Output

The type of the element with the two-way binding added.

Required Methods§

fn bind(self, key: Key, signal: Sig) -> Self::Output

Adds a two-way binding to the element, which adds an attribute and an event listener to the element when the element is created or hydrated.

Example:

ⓘ
// You can use `RwSignal`s
let is_awesome = RwSignal::new(true);

// And you can use split signals
let (text, set_text) = signal("Hello world".to_string());

// Use `Checked` and a `bool` signal for a checkbox
checkbox_element.bind(Checked, is_awesome);

// Use `Group` and `String` for radio inputs
radio_element.bind(Group, (text, set_text));

// Use `Value` and `String` for everything else
input_element.bind(Value, (text, set_text));

Depending on the input different events are listened to.

  • <input type="checkbox">, <input type="radio"> and <select> use the change event;
  • <input> with the rest of the types and <textarea> elements use the input event;

Implementors§

§

impl<V, Key, Sig, T> BindAttribute<Key, Sig, T> for V
where V: AddAnyAttr, Key: AttributeKey, Sig: IntoSplitSignal<Value = T>, T: FromEventTarget + AttributeValue + PartialEq + Sync + 'static, Signal<BoolOrT<T>>: IntoProperty, <Sig as IntoSplitSignal>::Read: Get<Value = T> + Send + Sync + Clone + 'static, <Sig as IntoSplitSignal>::Write: Send + Clone + 'static, Element: GetValue<T>,

§

type Output = <V as AddAnyAttr>::Output<Bind<Key, T, <Sig as IntoSplitSignal>::Read, <Sig as IntoSplitSignal>::Write>>