Added error message when name field is empty
This commit is contained in:
parent
3fc7420245
commit
dcf535aa77
@ -110,3 +110,8 @@ form {
|
|||||||
width: 400px;
|
width: 400px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.error {
|
||||||
|
color: red;
|
||||||
|
text-align: center;
|
||||||
|
font-size: 1.2em;
|
||||||
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
use leptos::*;
|
|
||||||
use application::App;
|
use application::App;
|
||||||
|
use leptos::*;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
// set up logging
|
// set up logging
|
||||||
|
@ -19,13 +19,16 @@ pub fn Add() -> impl IntoView {
|
|||||||
|
|
||||||
let (name, set_name) = create_signal(String::from(""));
|
let (name, set_name) = create_signal(String::from(""));
|
||||||
let (group, set_group) = create_signal(String::from("A1"));
|
let (group, set_group) = create_signal(String::from("A1"));
|
||||||
|
let (error, set_error) = create_signal(String::from(""));
|
||||||
|
|
||||||
let on_submit = move |ev: leptos::ev::SubmitEvent| {
|
let on_submit = move |ev: leptos::ev::SubmitEvent| {
|
||||||
ev.prevent_default();
|
ev.prevent_default();
|
||||||
|
set_error.set(String::from(""));
|
||||||
|
|
||||||
websocket.add_person(name.get(), group.get());
|
match websocket.add_person(name.get(), group.get()) {
|
||||||
|
Ok(_) => set_name.set(String::from("")),
|
||||||
set_name.set(String::from(""))
|
Err(err) => set_error.set(err),
|
||||||
|
}
|
||||||
};
|
};
|
||||||
view! {
|
view! {
|
||||||
<h1>"Deelnemer toevoegen"</h1>
|
<h1>"Deelnemer toevoegen"</h1>
|
||||||
@ -80,5 +83,8 @@ pub fn Add() -> impl IntoView {
|
|||||||
/>
|
/>
|
||||||
<input type="submit" value="Submit" />
|
<input type="submit" value="Submit" />
|
||||||
</form>
|
</form>
|
||||||
|
<p class="error">
|
||||||
|
{ error }
|
||||||
|
</p>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -102,7 +102,11 @@ impl SurrealContext {
|
|||||||
self.send(&json!(request).to_string());
|
self.send(&json!(request).to_string());
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_person(&self, name: String, group: String) {
|
pub fn add_person(&self, name: String, group: String) -> Result<(), String> {
|
||||||
|
if name.is_empty() {
|
||||||
|
return Err(String::from("Name cannot be empty"));
|
||||||
|
}
|
||||||
|
|
||||||
let request = SurrealRequest {
|
let request = SurrealRequest {
|
||||||
id: 1,
|
id: 1,
|
||||||
method: String::from("create"),
|
method: String::from("create"),
|
||||||
@ -115,7 +119,7 @@ impl SurrealContext {
|
|||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
self.send(&json!(request).to_string())
|
Ok(self.send(&json!(request).to_string()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user