Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
a `<select multiple>`; `none_label` for a button which clears the selection, f. ex. "All"
of a filter; and the CSS of the container and of the buttons, selected or not
* `MultiSelect`: every button tells whether it is selected in `aria-pressed`
* `StringValue`, `ListValue`, `DictValue`, `MultiValue` and `BoolValue` exported from `form`, so
a field can be built on a `Value` shared with something else, f. ex. a preview that follows
what is typed. They were public but out of reach, so only `TextAreaValue`, `ImageValue` and
`CustomValue` could be built by hand

### Changed

Expand Down
30 changes: 30 additions & 0 deletions src/form/data/data_field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,38 @@ impl DataFieldValue {
}
}

/// Value of a [DataFieldValue::String] field.
///
/// Built by hand, a field can share its `Value` with something else, f. ex. a preview that
/// follows what is typed. [DataSection::with_string_field](super::DataSection::with_string_field)
/// creates a `Value` of its own instead.
///
/// ```rust
/// use std::rc::Rc;
/// use vertigo::{Value, transaction};
/// use vertigo_forms::form::{DataFieldValue, DataSection, StringValue};
///
/// let title = Value::new("Draft".to_string());
/// let section = DataSection::new("Title").add_field(
/// "title",
/// DataFieldValue::String(StringValue {
/// value: title.clone(),
/// original_value: Rc::new("Draft".to_string()),
/// }),
/// );
///
/// // Typing into the field changes `title` as well
/// let DataFieldValue::String(field) = &section.fields[0].value else { unreachable!() };
/// field.value.set("Final".to_string());
/// assert_eq!(transaction(|ctx| title.get(ctx)), "Final");
/// ```
#[derive(Clone)]
pub struct StringValue {
pub value: Value<String>,
pub original_value: Rc<String>,
}

/// Value of a [DataFieldValue::TextArea] field.
#[derive(Clone)]
pub struct TextAreaValue {
pub value: Value<String>,
Expand All @@ -60,20 +86,23 @@ pub struct TextAreaValue {
pub cols: Option<i32>,
}

/// Value of a [DataFieldValue::List] field.
#[derive(Clone)]
pub struct ListValue {
pub value: Value<String>,
pub original_value: Option<Rc<String>>,
pub options: Computed<Vec<String>>,
}

/// Value of a [DataFieldValue::Dict] field.
#[derive(Clone)]
pub struct DictValue {
pub value: Value<i64>,
pub original_value: Option<Rc<i64>>,
pub options: Computed<Vec<(i64, String)>>,
}

/// Value of a [DataFieldValue::Multi] field.
#[derive(Clone)]
pub struct MultiValue {
pub value: Value<Vec<Value<i64>>>,
Expand All @@ -82,6 +111,7 @@ pub struct MultiValue {
pub add_label: Rc<String>,
}

/// Value of a [DataFieldValue::Bool] field.
#[derive(Clone)]
pub struct BoolValue {
pub value: Value<bool>,
Expand Down
5 changes: 4 additions & 1 deletion src/form/data/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ use vertigo::Value;
use crate::ValidationErrors;

mod data_field;
pub use data_field::{CustomValue, DataFieldValue, ImageValue, TextAreaValue};
pub use data_field::{
BoolValue, CustomValue, DataFieldValue, DictValue, ImageValue, ListValue, MultiValue,
StringValue, TextAreaValue,
};

mod form_export;
pub use form_export::{FieldExport, FormExport};
Expand Down
Loading