1. migrated code to form.rs
2. made get_parsed_values as private fn. 3. handled multi-valued data while parsing
This commit is contained in:
1 parent
02e91d8b9a
commit
d54ec57192
2 files changed
+53
-25
No files matched your search
@@ -74,29 +74,6 @@ impl FormData {
|
||||
files: None,
|
||||
}
|
||||
}
|
||||
|
||||
// ***** function to parse the 'values' to make it ready to use*******
|
||||
// e.g - self.values = { username: ["rust"], password: ["dioxus"]}
|
||||
// what we need it to be: { username: "rust", password: "dioxus"}
|
||||
pub fn get_parsed_values(&self) -> Option<HashMap<String, String>> {
|
||||
if (self.values.is_empty()) {
|
||||
return None;
|
||||
}
|
||||
|
||||
let raw_values = self.values.clone();
|
||||
|
||||
let mut parsed_values: HashMap<String, String> = HashMap::new();
|
||||
|
||||
for (fieldname, values) in raw_values.into_iter() {
|
||||
// convert array of string value to string
|
||||
// eg - ["rust", "javascript"] => "rust, javascript"
|
||||
let prepared_value = values.join(", ");
|
||||
|
||||
parsed_values.insert(fieldname, prepared_value);
|
||||
}
|
||||
|
||||
Some(parsed_values)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
|
||||
Reference in new issue
Block a user