Explorar o código

document parsed_values and FormValue

ealmloff hai 1 ano
pai
achega
20bbf95979
Modificáronse 1 ficheiros con 4 adicións e 2 borrados
  1. 4 2
      packages/html/src/events/form.rs

+ 4 - 2
packages/html/src/events/form.rs

@@ -5,9 +5,10 @@ use serde::{Deserialize, Serialize};
 
 pub type FormEvent = Event<FormData>;
 
+/// A form value that may either be a list of values or a single value
 #[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
 #[serde(untagged)] // this will serialize Text(String) -> String and VecText(Vec<String>) to Vec<String>
-pub enum ValueType {
+pub enum FormValue {
     Text(String),
     VecText(Vec<String>),
 }
@@ -18,7 +19,7 @@ pub enum ValueType {
 pub struct FormData {
     pub value: String,
 
-    pub values: HashMap<String, ValueType>,
+    pub values: HashMap<String, FormValue>,
 
     #[cfg_attr(
         feature = "serialize",
@@ -40,6 +41,7 @@ where
 }
 
 impl FormData {
+    /// Parse the values into a struct with one field per value
     pub fn parsed_values<T>(&self) -> Result<T, serde_json::Error>
     where
         T: serde::de::DeserializeOwned,