From 4045779947e9e9c36ce385b298434c88278be802 Mon Sep 17 00:00:00 2001 From: eiiko6 Date: Mon, 1 Dec 2025 18:54:09 +0100 Subject: [PATCH] config: added custom html insertion and separated name and title --- src/main.rs | 6 ++++++ templates/form.html | 11 ++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/main.rs b/src/main.rs index e880d46..810169b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -18,13 +18,17 @@ use tower_http::cors::{Any, CorsLayer}; #[derive(Debug, Deserialize)] struct FieldDef { name: String, + title: String, description: String, answer_type: String, + html_before: Option, + html_after: Option, } #[derive(Debug, Deserialize)] struct AppConfig { json_output: String, + submit_button: String, fields: Vec, } @@ -111,11 +115,13 @@ async fn render_form(State(state): State) -> impl IntoResponse { struct FormTemplate<'a> { fields: &'a [FieldDef], lang: &'a str, + submit_button: &'a str, } let tmpl = FormTemplate { fields: &state.cfg.fields, lang: "en", + submit_button: &state.cfg.submit_button, }; match tmpl.render() { Ok(html) => Html(html).into_response(), diff --git a/templates/form.html b/templates/form.html index df5e51c..fa5d1d2 100644 --- a/templates/form.html +++ b/templates/form.html @@ -3,11 +3,13 @@ {% block title %}Form{% endblock %} {% block content %} -

Dynamic Form

{% for f in fields %} + {% if f.html_before.is_some() %} + {{ f.html_before.as_ref().unwrap() | safe }} + {% endif %}
- +
{{ f.description }}
{% if f.answer_type == "textarea" %} @@ -17,8 +19,11 @@ {% endif %}
+ {% if f.html_after.is_some() %} + {{ f.html_after.as_ref().unwrap() | safe }} + {% endif %} {% endfor %} -
+
{% endblock %}