mirror of
https://github.com/DioxusLabs/dioxus
synced 2025-02-18 14:48:26 +00:00
document parsed_values and FormValue
This commit is contained in:
parent
67670875bb
commit
20bbf95979
1 changed files with 4 additions and 2 deletions
|
@ -5,9 +5,10 @@ use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
pub type FormEvent = Event<FormData>;
|
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)]
|
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
|
||||||
#[serde(untagged)] // this will serialize Text(String) -> String and VecText(Vec<String>) to Vec<String>
|
#[serde(untagged)] // this will serialize Text(String) -> String and VecText(Vec<String>) to Vec<String>
|
||||||
pub enum ValueType {
|
pub enum FormValue {
|
||||||
Text(String),
|
Text(String),
|
||||||
VecText(Vec<String>),
|
VecText(Vec<String>),
|
||||||
}
|
}
|
||||||
|
@ -18,7 +19,7 @@ pub enum ValueType {
|
||||||
pub struct FormData {
|
pub struct FormData {
|
||||||
pub value: String,
|
pub value: String,
|
||||||
|
|
||||||
pub values: HashMap<String, ValueType>,
|
pub values: HashMap<String, FormValue>,
|
||||||
|
|
||||||
#[cfg_attr(
|
#[cfg_attr(
|
||||||
feature = "serialize",
|
feature = "serialize",
|
||||||
|
@ -40,6 +41,7 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FormData {
|
impl FormData {
|
||||||
|
/// Parse the values into a struct with one field per value
|
||||||
pub fn parsed_values<T>(&self) -> Result<T, serde_json::Error>
|
pub fn parsed_values<T>(&self) -> Result<T, serde_json::Error>
|
||||||
where
|
where
|
||||||
T: serde::de::DeserializeOwned,
|
T: serde::de::DeserializeOwned,
|
||||||
|
|
Loading…
Add table
Reference in a new issue