]> saetta.ns0.it Git - rust/zakform/commitdiff
Deny adding fields with equal name.
authorAndrea Zagli <azagli@libero.it>
Tue, 21 Oct 2025 08:27:23 +0000 (10:27 +0200)
committerAndrea Zagli <azagli@libero.it>
Tue, 21 Oct 2025 08:27:23 +0000 (10:27 +0200)
src/form.rs

index d5b8ca6e2a7f40cea303532c6dab5228c6e3bdf1..3b2de56c649b8fbbd3c107e204a8c2a772d48cb5 100644 (file)
@@ -15,7 +15,10 @@ impl Form {
        }
 
        pub fn add_field(&mut self, field: Box<dyn super::fields::TField>) {
-               self.fields.push(field);
+               /* check if already exists with this name */
+               if !self.get_field(&field.get_name()).is_ok() {
+                       self.fields.push(field);
+               }
        }
 
        pub fn remove_field(&mut self, field_name: &str) {