From: Andrea Zagli Date: Tue, 7 Feb 2023 16:14:41 +0000 (+0100) Subject: Added function Field::set_template. X-Git-Url: https://saetta.ns0.it/gitweb?a=commitdiff_plain;h=4961036719d851989ea693f6536986b747bef706;p=rust%2Fzakform Added function Field::set_template. --- diff --git a/examples/form.rs b/examples/form.rs index 8392fcd..2e560cd 100644 --- a/examples/form.rs +++ b/examples/form.rs @@ -72,6 +72,11 @@ async fn index_post( fi.set_value(map.get(fi.name().as_str()).unwrap().as_str()); fi.add_filter(filters::filter_uppercase); fi.filter(); + fi.set_template(r#"{% if label %}
+ {% endif %} + 0 %}maxlength="{{ maxlen }}"{% endif %} {% if invisible %}style="display: none;"{% endif %}/> + {% if help %}
{{ help }}
{% endif %} + {% if label %}
{% endif %}"#); f.add_field(fi); let mut fi = zakform::Field::new(zakform::FType::TextArea, "notes"); @@ -122,6 +127,11 @@ async fn index( let mut fi = zakform::Field::new(zakform::FType::Text, "name"); fi.set_label("Name"); + fi.set_template(r#"{% if label %}
+ {% endif %} + 0 %}maxlength="{{ maxlen }}"{% endif %} {% if invisible %}style="display: none;"{% endif %}/> + {% if help %}
{{ help }}
{% endif %} + {% if label %}
{% endif %}"#); f.add_field(fi); let mut fi = zakform::Field::new(zakform::FType::TextArea, "notes"); diff --git a/src/lib.rs b/src/lib.rs index 43b0f31..05474f4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -145,6 +145,10 @@ impl Field { self.options.push(option); } + pub fn set_template(&mut self, template: &str) { + self.tmpl.add_raw_template("field", template); + } + pub fn add_filter(&mut self, filter: filters::Filter) { self.filters.push(filter); }