pub struct ZakFormElementValidator {
#[serde(rename = "@type")]
pub vtype: String,
+ #[serde(rename = "@type_comp")]
+ pub type_comp: String,
+ #[serde(rename = "@value_comp")]
+ pub value_comp: String,
+ #[serde(rename = "$text")]
+ pub text: String,
}
#[derive(Default, Debug, Clone, PartialEq, Deserialize)]
};
}
- for validator in e.validators {
+ for (i, validator) in e.validators.into_iter().enumerate() {
match validator.vtype.as_str() {
"zak_form_element_validator_notempty" => { writeln!(output, r#"fi.add_validator(Box::new(zakform::validators::ValidatorNotEmpty::new("{}_notempty")));"#, e.id); },
+ "zak_form_element_validator_date" => {
+ writeln!(output, r#"let mut v = zakform::validators::ValidatorDate::new("{}_date_{}");"#, e.id, i);
+
+ match validator.type_comp.as_str() {
+ "lt" => { writeln!(output, "v.set_compare_type(Some(zakform::validators::ValidatorDateCompareType::Less));"); },
+ "let" => { writeln!(output, "v.set_compare_type(Some(zakform::validators::ValidatorDateCompareType::LessEq));"); },
+ "e" => { writeln!(output, "v.set_compare_type(Some(zakform::validators::ValidatorDateCompareType::Eq));"); },
+ "ne" => {},
+ "gt" => { writeln!(output, "v.set_compare_type(Some(zakform::validators::ValidatorDateCompareType::Great));"); },
+ "get" => { writeln!(output, "v.set_compare_type(Some(zakform::validators::ValidatorDateCompareType::GreatEq));"); },
+ _ => { },
+ };
+
+ if validator.value_comp != "" {
+ writeln!(output, r#"v.set_compare_value(Some("{}"));"#, validator.value_comp);
+ }
+
+ writeln!(output, "fi.add_validator(Box::new(v));");
+ },
_ => { },
};
}