From c4dbb3545082732290d91529ec9d57e2d5e52064 Mon Sep 17 00:00:00 2001 From: Andrea Zagli Date: Sun, 24 Sep 2023 12:32:50 +0200 Subject: [PATCH] Added field class attribute. --- src/fields.rs | 66 +++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 59 insertions(+), 7 deletions(-) diff --git a/src/fields.rs b/src/fields.rs index b0c5e2a..8ead055 100644 --- a/src/fields.rs +++ b/src/fields.rs @@ -22,6 +22,7 @@ struct Field { invisible: bool, help: String, value: String, + class: String, to_load: bool, to_save: bool, to_render: bool, @@ -48,6 +49,9 @@ pub trait TField { fn get_value(&self) -> String; fn set_value(&mut self, value: &str); + fn get_class(&self) -> String; + fn set_class(&mut self, value: &str); + fn get_to_load(&self) -> bool; fn set_to_load(&mut self, to_load: bool); @@ -122,6 +126,14 @@ impl TField for FieldText { self.field.value = String::from(value); } + fn get_class(&self) -> String { + String::from(&self.field.class) + } + + fn set_class(&mut self, value: &str) { + self.field.value = String::from(value); + } + fn get_to_load(&self) -> bool { self.field.to_load } @@ -207,7 +219,7 @@ impl FieldText { match f.field.tmpl.add_raw_template("field", r#"{% if label %}
{% endif %} - 0 %}maxlength="{{ maxlen }}"{% endif %} {% if invisible %}style="display: none;"{% endif %}/> + 0 %}maxlength="{{ maxlen }}"{% endif %} {% if invisible %}style="display: none;"{% endif %}/> {% if help %}
{{ help }}
{% endif %} {% if label %}
{% endif %}"#) { Err(e) => { println!("{:?}", e) }, @@ -278,6 +290,14 @@ impl TField for FieldTextArea { self.field.value = String::from(value); } + fn get_class(&self) -> String { + String::from(&self.field.class) + } + + fn set_class(&mut self, value: &str) { + self.field.value = String::from(value); + } + fn get_to_load(&self) -> bool { self.field.to_load } @@ -366,7 +386,7 @@ impl FieldTextArea { match f.field.tmpl.add_raw_template("field", r#"{% if label %}
{% endif %} - {% if help %}
{{ help }}
{% endif %} {% if label %}
{% endif %}"#) { @@ -451,6 +471,14 @@ impl TField for FieldRadio { self.field.value = String::from(value); } + fn get_class(&self) -> String { + String::from(&self.field.class) + } + + fn set_class(&mut self, value: &str) { + self.field.value = String::from(value); + } + fn get_to_load(&self) -> bool { self.field.to_load } @@ -538,7 +566,7 @@ impl FieldRadio {
{% endif %} {% for o in options %}
- +
{% endfor %} @@ -549,7 +577,7 @@ _ => {}, }; match f.field.tmpl.add_raw_template("field_single", r#"
- +
"#) { Err(e) => { println!("{:?}", e) }, @@ -652,6 +680,14 @@ impl TField for FieldSelect { self.field.value = String::from(value); } + fn get_class(&self) -> String { + String::from(&self.field.class) + } + + fn set_class(&mut self, value: &str) { + self.field.value = String::from(value); + } + fn get_to_load(&self) -> bool { self.field.to_load } @@ -737,7 +773,7 @@ impl FieldSelect { match f.field.tmpl.add_raw_template("field", r#"{% if label %}

{% endif %} - {% for o in options %} {% endfor %} @@ -818,6 +854,14 @@ impl TField for FieldCheck { self.field.value = String::from(value); } + fn get_class(&self) -> String { + String::from(&self.field.class) + } + + fn set_class(&mut self, value: &str) { + self.field.value = String::from(value); + } + fn get_to_load(&self) -> bool { self.field.to_load } @@ -901,7 +945,7 @@ impl FieldCheck { f.field.to_render = true; match f.field.tmpl.add_raw_template("field", r#"
- + {% if label %}{% endif %} {% if help %}
{{ help }}
{% endif %}
"#) { @@ -964,6 +1008,14 @@ impl TField for FieldButton { self.field.value = String::from(value); } + fn get_class(&self) -> String { + String::from(&self.field.class) + } + + fn set_class(&mut self, value: &str) { + self.field.value = String::from(value); + } + fn get_to_load(&self) -> bool { self.field.to_load } @@ -1045,7 +1097,7 @@ impl FieldButton { f.field.label = String::from(name); f.field.to_render = true; - match f.field.tmpl.add_raw_template("field", r#""#) { Err(e) => { println!("{:?}", e) }, _ => {}, -- 2.49.0