#[derive(Debug)]
pub struct WizardStep {
pub id: usize,
pub name: String,
pub description: String,
pub fields: Vec<InputField>,
pub optional: bool,
}
impl Clone for WizardStep {
fn clone(&self) -> Self {
Self {
id: self.id,
name: self.name.clone(),
description: self.description.clone(),
fields: self
.fields
.iter()
.map(|f| InputField {
name: f.name.clone(),
field_type: f.field_type.clone(),
label: f.label.clone(),
help_text: f.help_text.clone(),
default: f.default.clone(),
validators: Vec::new(), })
.collect(),
optional: self.optional,
}
}
}
pub struct InputField {
pub name: String,
pub field_type: FieldType,
pub label: String,
pub help_text: Option<String>,
pub default: Option<String>,
pub validators: Vec<Validator>,
}
impl std::fmt::Debug for InputField {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("InputField")
.field("name", &self.name)
.field("field_type", &self.field_type)
.field("label", &self.label)
.field("help_text", &self.help_text)
.field("default", &self.default)
.field(
"validators",
&format!("{} validators", self.validators.len()),
)
.finish()
}
}
#[derive(Debug, Clone)]
pub enum FieldType {
Text,
Password,
MultilineText,
Confirm { default: bool },
Select { options: Vec<String> },
MultiSelect { options: Vec<String> },
}
pub enum Validator {
Required,
MinLength(usize),
MaxLength(usize),
Url,
Custom(Box<dyn Fn(&str) -> Result<(), String>>),
}