Replace the input! macro with an Input builder (#646)

* Replace the input! macro with an Input builder

* Use a BTreeMap instead of an HashMap

Followinf @fdb-hiroshima's advice

* Rename Input::to_html to Input::html

To make clippy happy

* Wrap error messages in red paragraphs
This commit is contained in:
Ana Gelez
2019-08-27 16:50:24 +02:00
committed by Igor Galić
parent 935d331e97
commit 8ab690001d
14 changed files with 297 additions and 146 deletions
+20 -5
View File
@@ -25,8 +25,15 @@
} else {
<form id="plume-fallback-editor" class="new-post" method="post" action="@uri!(posts::new: blog = blog.actor_id)" content-size="@content_len">
}
@input!(ctx.1, title (text), "Title", form, errors.clone(), "required")
@input!(ctx.1, subtitle (optional text), "Subtitle", form, errors.clone(), "")
@(Input::new("title", i18n!(ctx.1, "Title"))
.default(&form.title)
.error(&errors)
.html(ctx.1))
@(Input::new("subtitle", i18n!(ctx.1, "Subtitle"))
.default(&form.subtitle)
.error(&errors)
.optional()
.html(ctx.1))
@if let Some(ValidationErrorsKind::Field(errs)) = errors.clone().errors().get("content") {
@format!(r#"<p class="error">{}</p>"#, errs[0].message.clone().unwrap_or_else(|| Cow::from("Unknown error")))
@@ -40,9 +47,17 @@
<a href="@uri!(medias::new)">@i18n!(ctx.1, "Upload media")</a>
</p>
@input!(ctx.1, tags (optional text), "Tags, separated by commas", form, errors.clone(), "")
@input!(ctx.1, license (optional text), "License", "Leave it empty to reserve all rights", form, errors, "")
@(Input::new("tags", i18n!(ctx.1, "Tags, separated by commas"))
.default(&form.tags)
.error(&errors)
.optional()
.html(ctx.1))
@(Input::new("license", i18n!(ctx.1, "License"))
.default(&form.license)
.error(&errors)
.optional()
.details("Leave it empty to reserve all rights")
.html(ctx.1))
@:image_select(ctx, "cover", i18n!(ctx.1, "Illustration"), true, medias, form.cover)