diff --git a/src/controls/button.rs b/src/controls/button.rs index ee03f53..14bdd99 100644 --- a/src/controls/button.rs +++ b/src/controls/button.rs @@ -7,8 +7,8 @@ use web_sys::MouseEvent; type ButtonAction = dyn Fn(MouseEvent, RwSignal) + 'static; pub struct ButtonData { - pub(crate) text: String, - pub(crate) action: Option>>, + pub text: String, + pub action: Option>>, } impl Default for ButtonData { fn default() -> Self { diff --git a/src/controls/checkbox.rs b/src/controls/checkbox.rs index f74f714..f22a433 100644 --- a/src/controls/checkbox.rs +++ b/src/controls/checkbox.rs @@ -4,8 +4,8 @@ use leptos::{Signal, View}; #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Default)] pub struct CheckboxData { - pub(crate) name: String, - pub(crate) label: Option, + pub name: String, + pub label: Option, } impl ControlData for CheckboxData { diff --git a/src/controls/heading.rs b/src/controls/heading.rs index 4e22d4b..bc0a7fa 100644 --- a/src/controls/heading.rs +++ b/src/controls/heading.rs @@ -4,7 +4,7 @@ use leptos::View; #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Default)] pub struct HeadingData { - pub(crate) title: String, + pub title: String, } impl VanityControlData for HeadingData { diff --git a/src/controls/radio_buttons.rs b/src/controls/radio_buttons.rs index 2212a27..b2a6c5d 100644 --- a/src/controls/radio_buttons.rs +++ b/src/controls/radio_buttons.rs @@ -4,9 +4,9 @@ use leptos::{Signal, View}; #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Default)] pub struct RadioButtonsData { - pub(crate) name: String, - pub(crate) label: Option, - pub(crate) options: Vec, + pub name: String, + pub label: Option, + pub options: Vec, } impl ControlData for RadioButtonsData { diff --git a/src/controls/select.rs b/src/controls/select.rs index cb84ce5..7a20b49 100644 --- a/src/controls/select.rs +++ b/src/controls/select.rs @@ -4,12 +4,12 @@ use leptos::{Signal, View}; #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Default)] pub struct SelectData { - pub(crate) name: String, - pub(crate) label: Option, + pub name: String, + pub label: Option, /// The options for the select. /// /// The first value is the string to display, the second is the value. - pub(crate) options: Vec<(String, String)>, + pub options: Vec<(String, String)>, } impl ControlData for SelectData { diff --git a/src/controls/slider.rs b/src/controls/slider.rs index 9f9cb50..24f8d8b 100644 --- a/src/controls/slider.rs +++ b/src/controls/slider.rs @@ -5,10 +5,10 @@ use std::ops::RangeInclusive; #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct SliderData { - pub(crate) name: String, - pub(crate) label: Option, - pub(crate) min: i32, - pub(crate) max: i32, + pub name: String, + pub label: Option, + pub min: i32, + pub max: i32, } impl Default for SliderData { diff --git a/src/controls/spacer.rs b/src/controls/spacer.rs index 6d19b23..b6bcafa 100644 --- a/src/controls/spacer.rs +++ b/src/controls/spacer.rs @@ -4,7 +4,7 @@ use leptos::{prelude::Signal, View}; #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Default)] pub struct SpacerData { - pub(crate) height: Option, + pub height: Option, } impl VanityControlData for SpacerData { diff --git a/src/controls/stepper.rs b/src/controls/stepper.rs index f52c662..975b8c0 100644 --- a/src/controls/stepper.rs +++ b/src/controls/stepper.rs @@ -5,11 +5,11 @@ use std::ops::RangeInclusive; #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Default)] pub struct StepperData { - pub(crate) name: String, - pub(crate) label: Option, - pub(crate) step: Option, - pub(crate) min: Option, - pub(crate) max: Option, + pub name: String, + pub label: Option, + pub step: Option, + pub min: Option, + pub max: Option, } impl ControlData for StepperData { diff --git a/src/controls/submit.rs b/src/controls/submit.rs index 28a8c9b..8907894 100644 --- a/src/controls/submit.rs +++ b/src/controls/submit.rs @@ -4,7 +4,7 @@ use leptos::{prelude::Signal, View}; #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Default)] pub struct SubmitData { - pub(crate) text: String, + pub text: String, } impl VanityControlData for SubmitData { diff --git a/src/controls/text_area.rs b/src/controls/text_area.rs index d16c06f..064bd64 100644 --- a/src/controls/text_area.rs +++ b/src/controls/text_area.rs @@ -4,8 +4,8 @@ use leptos::{Signal, View}; #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Default)] pub struct TextAreaData { - pub(crate) name: String, - pub(crate) placeholder: Option, + pub name: String, + pub placeholder: Option, } impl ControlData for TextAreaData { diff --git a/src/controls/text_input.rs b/src/controls/text_input.rs index 7bfc063..0c38a64 100644 --- a/src/controls/text_input.rs +++ b/src/controls/text_input.rs @@ -4,11 +4,11 @@ use leptos::{Signal, View}; #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct TextInputData { - pub(crate) name: String, - pub(crate) placeholder: Option, - pub(crate) label: Option, - pub(crate) initial_text: String, - pub(crate) input_type: &'static str, + pub name: String, + pub placeholder: Option, + pub label: Option, + pub initial_text: String, + pub input_type: &'static str, } impl Default for TextInputData { diff --git a/src/form_builder.rs b/src/form_builder.rs index 5d5a964..e2ccf47 100644 --- a/src/form_builder.rs +++ b/src/form_builder.rs @@ -221,6 +221,59 @@ impl FormBuilder { Box::new(value_setter) } + // TODO: impl build_formless function that builds the form without adding + // and form components around anything + + pub(crate) fn build_form( + self, + action: Action>>, + fd: FD, + fs: FD::Style, + ) -> Form + where + ServFn: DeserializeOwned + ServerFn + 'static, + <>::Request as ClientReq>::FormData: + From, + { + let fd = create_rw_signal(fd); + + let (views, validation_cbs): (Vec<_>, Vec<_>) = self + .render_fns + .into_iter() + .map(|r_fn| r_fn(&fs, fd)) + .unzip(); + + let elements = fs.form_frame(ControlRenderData { + data: views.into_view(), + styles: self.styles, + }); + + let on_submit = move |ev: SubmitEvent| { + let mut failed = false; + for validation in validation_cbs.iter().flatten() { + if !validation() { + failed = true; + } + } + if failed { + ev.prevent_default(); + } + }; + + // TODO: do enhanced form with direct calling of the server_fn + let view = view! { + + {elements} + + }; + + Form { + fd, + validations: self.validations, + view, + } + } + pub(crate) fn build_action_form( self, action: Action>>,