]> saetta.ns0.it Git - rust/zakform/commitdiff
c2rs: added support for validator is_number.
authorAndrea Zagli <azagli@libero.it>
Sun, 21 Jan 2024 08:59:31 +0000 (09:59 +0100)
committerAndrea Zagli <azagli@libero.it>
Sun, 21 Jan 2024 08:59:31 +0000 (09:59 +0100)
src/bin/c2rs.rs

index 0718798495d0f79a2aff19a561f271167bbf5c53..fe9e9217c2be1cd7fe3f3b233e5dca84b6957fcd 100644 (file)
@@ -104,6 +104,10 @@ pub struct ZakFormElementValidator {
        pub type_comp: String,
        #[serde(rename = "@value_comp")]
        pub value_comp: String,
+       #[serde(rename = "@plus_minus")]
+       pub plus_minus: String,
+       #[serde(rename = "@thousands_separator")]
+       pub thousands_separator: String,
        #[serde(rename = "$text")]
        pub text: String,
 }
@@ -276,6 +280,20 @@ fn main() {
 
                                        writeln!(output, "fi.add_validator(Box::new(v));");
                                },
+                               "zak_form_element_validator_is_number" => {
+                                       writeln!(output, r#"let mut v = zakform::validators::ValidatorNumber::new("{}_number_{}");"#, e.id, i);
+
+                                       if validator.plus_minus == "TRUE" {
+                                               writeln!(output, "v.set_plus_minus(true);");
+                                       }
+                                       if validator.thousands_separator != "" {
+                                               writeln!(output, "v.set_thousands_separator(Some('{}'));", validator.thousands_separator.as_str().chars().nth(0).unwrap());
+                                       } else {
+                                               writeln!(output, "v.set_thousands_separator(None);");
+                                       }
+
+                                       writeln!(output, "fi.add_validator(Box::new(v));");
+                               },
                                _ => { },
                        };
                }