Lines
0 %
Functions
Branches
100 %
//! Wires up every server-rendered `form.nomi-form` of the document.
use wasm_bindgen::prelude::*;
use web_sys::HtmlFormElement;
use crate::{conversion, dates, filled_marks, rows, suggest};
/// Make a rendered form behave: editable rows, date controls, the
/// converted amount and suggestions follow their inputs.
///
/// # Errors
/// Returns the DOM error if a listener or attribute cannot be set up.
pub fn init_form(form: &HtmlFormElement) -> Result<(), JsValue> {
rows::init_rows(form)?;
dates::init_dates(form)?;
conversion::init_conversion(form)?;
suggest::init_suggest(form)?;
filled_marks::init_filled_marks(form)
}
/// Initialise every server-rendered form of the document.
pub fn init_all() {
let Some(root) = web_sys::window()
.and_then(|w| w.document())
.and_then(|d| d.document_element())
else {
return;
};
let Ok(forms) = rows::each_element(&root, "form.nomi-form") else {
for form in forms.into_iter().filter_map(|f| f.dyn_into().ok()) {
if let Err(error) = init_form(&form) {
web_sys::console::error_1(&error);