diff --git a/Cargo.lock b/Cargo.lock index e2075b835f7..5aebdbf0e6c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -867,6 +867,15 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" +[[package]] +name = "form" +version = "0.1.0" +dependencies = [ + "js-sys", + "web-sys", + "yew", +] + [[package]] name = "form_urlencoded" version = "1.2.0" @@ -1844,9 +1853,9 @@ dependencies = [ [[package]] name = "js-sys" -version = "0.3.64" +version = "0.3.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c5f195fe497f702db0f318b07fdd68edb16955aed830df8363d837542f8f935a" +checksum = "29c15563dc2726973df627357ce0c9ddddbea194836909d655df6a75d2cf296d" dependencies = [ "wasm-bindgen", ] @@ -2112,16 +2121,6 @@ dependencies = [ "yew", ] -[[package]] -name = "nu-ansi-term" -version = "0.46.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77a8165726e8236064dbb45459242600304b42a5ea24ee2948e18e023bf7ba84" -dependencies = [ - "overload", - "winapi", -] - [[package]] name = "num-traits" version = "0.2.15" @@ -2207,12 +2206,6 @@ dependencies = [ "vcpkg", ] -[[package]] -name = "overload" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39" - [[package]] name = "papergrid" version = "0.10.0" @@ -2787,15 +2780,6 @@ dependencies = [ "digest", ] -[[package]] -name = "sharded-slab" -version = "0.1.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f40ca3c46823713e0d4209592e8d6e826aa57e928f09752619fc696c499637f6" -dependencies = [ - "lazy_static", -] - [[package]] name = "signal-hook-registry" version = "1.4.1" @@ -2812,14 +2796,14 @@ dependencies = [ "bytes", "clap", "futures 0.3.29", + "log", "reqwest", "serde", - "time", "tokio", - "tracing-subscriber", - "tracing-web", "uuid", "warp", + "wasm-bindgen-futures", + "wasm-logger", "yew", ] @@ -3058,16 +3042,6 @@ dependencies = [ "syn 2.0.38", ] -[[package]] -name = "thread_local" -version = "1.1.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b9ef9bad013ada3808854ceac7b46812a6465ba368859a37e2100283d2d719c" -dependencies = [ - "cfg-if", - "once_cell", -] - [[package]] name = "time" version = "0.3.30" @@ -3075,7 +3049,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c4a34ab300f2dee6e562c10a046fc05e358b29f9bf92277f30c3c8d82275f6f5" dependencies = [ "deranged", - "js-sys", "powerfmt", "serde", "time-core", @@ -3310,45 +3283,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" dependencies = [ "once_cell", - "valuable", -] - -[[package]] -name = "tracing-log" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee855f1f400bd0e5c02d150ae5de3840039a3f54b025156404e34c23c03f47c3" -dependencies = [ - "log", - "once_cell", - "tracing-core", -] - -[[package]] -name = "tracing-subscriber" -version = "0.3.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ad0f048c97dbd9faa9b7df56362b8ebcaa52adb06b498c050d2f4e32f90a7a8b" -dependencies = [ - "nu-ansi-term", - "sharded-slab", - "smallvec", - "thread_local", - "tracing-core", - "tracing-log", -] - -[[package]] -name = "tracing-web" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b9e6a141feebd51f8d91ebfd785af50fca223c570b86852166caa3b141defe7c" -dependencies = [ - "js-sys", - "tracing-core", - "tracing-subscriber", - "wasm-bindgen", - "web-sys", ] [[package]] @@ -3485,12 +3419,6 @@ dependencies = [ "serde", ] -[[package]] -name = "valuable" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" - [[package]] name = "vcpkg" version = "0.2.15" @@ -3551,9 +3479,9 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasm-bindgen" -version = "0.2.87" +version = "0.2.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7706a72ab36d8cb1f80ffbf0e071533974a60d0a308d01a5d0375bf60499a342" +checksum = "4be2531df63900aeb2bca0daaaddec08491ee64ceecbee5076636a3b026795a8" dependencies = [ "cfg-if", "wasm-bindgen-macro", @@ -3561,9 +3489,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.87" +version = "0.2.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ef2b6d3c510e9625e5fe6f509ab07d66a760f0885d858736483c32ed7809abd" +checksum = "614d787b966d3989fa7bb98a654e369c762374fd3213d212cfc0251257e747da" dependencies = [ "bumpalo", "log", @@ -3588,9 +3516,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.87" +version = "0.2.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dee495e55982a3bd48105a7b947fd2a9b4a8ae3010041b9e0faab3f9cd028f1d" +checksum = "a1f8823de937b71b9460c0c34e25f3da88250760bec0ebac694b49997550d726" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -3598,9 +3526,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.87" +version = "0.2.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "54681b18a46765f095758388f2d0cf16eb8d4169b639ab575a8f5693af210c7b" +checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7" dependencies = [ "proc-macro2", "quote", @@ -3611,9 +3539,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.87" +version = "0.2.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca6ad05a4870b2bf5fe995117d3728437bd27d7cd5f06f13c17443ef369775a1" +checksum = "af190c94f2773fdb3729c55b007a722abb5384da03bc0986df4c289bf5567e96" [[package]] name = "wasm-bindgen-test" @@ -3652,9 +3580,9 @@ dependencies = [ [[package]] name = "web-sys" -version = "0.3.64" +version = "0.3.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b85cbef8c220a6abc02aefd892dfc0fc23afb1c6a426316ec33253a3877249b" +checksum = "77afa9a11836342370f4817622a2f0f418b134426d91a82dfb48f532d2ec13ef" dependencies = [ "js-sys", "wasm-bindgen", diff --git a/examples/form/Cargo.toml b/examples/form/Cargo.toml new file mode 100644 index 00000000000..c027fd47c9d --- /dev/null +++ b/examples/form/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "form" +version = "0.1.0" +authors = ["Kenzi Connor "] +edition = "2021" +license = "Unlicense" + +[dependencies] +js-sys = "0.3" +yew = { path = "../../packages/yew", features = ["csr"] } + +[dependencies.web-sys] +version = "0.3.69" +features = ["FormData", "HtmlFormElement"] diff --git a/examples/form/README.md b/examples/form/README.md new file mode 100644 index 00000000000..8b9271b4b9e --- /dev/null +++ b/examples/form/README.md @@ -0,0 +1,13 @@ +# Form Example + +[![Demo](https://img.shields.io/website?label=demo&url=https%3A%2F%2Fexamples.yew.rs%2Fform)](https://examples.yew.rs/form) + +This example demonstrates using a form and FormData instead of accessing the fields individually other ways + +## Running + +Run this application with the trunk development server: + +```bash +trunk serve --open +``` \ No newline at end of file diff --git a/examples/form/index.html b/examples/form/index.html new file mode 100644 index 00000000000..270ee96b607 --- /dev/null +++ b/examples/form/index.html @@ -0,0 +1,11 @@ + + + + + Yew • Form + + + + + + diff --git a/examples/form/src/main.rs b/examples/form/src/main.rs new file mode 100644 index 00000000000..7921e077684 --- /dev/null +++ b/examples/form/src/main.rs @@ -0,0 +1,59 @@ +use web_sys::{FormData, HtmlFormElement}; +use yew::prelude::*; + +pub enum Msg { + Submit(SubmitEvent), +} + +pub struct App { + names: Vec, +} + +impl Component for App { + type Message = Msg; + type Properties = (); + + fn create(_ctx: &Context) -> Self { + Self { + names: Vec::default(), + } + } + + fn update(&mut self, _ctx: &Context, msg: Self::Message) -> bool { + match msg { + Msg::Submit(event) => { + event.prevent_default(); + let form: HtmlFormElement = event.target_unchecked_into(); + let form_data = FormData::new_with_form(&form).expect("form data"); + self.names.push(format!( + "{} {}", + form_data.get("first").as_string().unwrap(), + form_data.get("last").as_string().unwrap() + )); + } + } + true + } + + fn view(&self, ctx: &Context) -> Html { + html! { +
+
+ + + + +
+
    + { for self.names.iter().map( |name| html! { +
  • { name }
  • + })} +
+
+ } + } +} + +fn main() { + yew::Renderer::::new().render(); +}