Display errors on invalid forms

It will probably need a bit of styling…
This commit is contained in:
Bat
2018-07-06 19:29:36 +02:00
parent 153400959c
commit 5f3afe900f
12 changed files with 68 additions and 39 deletions
+7 -4
View File
@@ -77,12 +77,14 @@ fn new(blog: String, user: User, conn: DbConn) -> Template {
}))
} else {
Template::render("posts/new", json!({
"account": user
"account": user,
"errors": null,
"form": null
}))
}
}
#[derive(FromForm, Validate)]
#[derive(FromForm, Validate, Serialize)]
struct NewPostForm {
#[validate(custom = "valid_slug")]
pub title: String,
@@ -113,7 +115,7 @@ fn create(blog_name: String, data: LenientForm<NewPostForm>, user: User, conn: D
Err(e) => e
};
if let Err(e) = slug_taken_err {
errors.add("title", e)
errors.add("title", e);
}
if errors.is_empty() {
@@ -150,7 +152,8 @@ fn create(blog_name: String, data: LenientForm<NewPostForm>, user: User, conn: D
} else {
Err(Template::render("posts/new", json!({
"account": user,
"errors": errors.inner()
"errors": errors.inner(),
"form": form
})))
}
}