generated from mitchell/rust_template
change the privacy modifiers on the ControlData
This commit is contained in:
parent
7d855e764f
commit
0339a2ee96
@ -7,8 +7,8 @@ use web_sys::MouseEvent;
|
|||||||
type ButtonAction<FD> = dyn Fn(MouseEvent, RwSignal<FD>) + 'static;
|
type ButtonAction<FD> = dyn Fn(MouseEvent, RwSignal<FD>) + 'static;
|
||||||
|
|
||||||
pub struct ButtonData<FD: FormToolData> {
|
pub struct ButtonData<FD: FormToolData> {
|
||||||
pub(crate) text: String,
|
pub text: String,
|
||||||
pub(crate) action: Option<Rc<ButtonAction<FD>>>,
|
pub action: Option<Rc<ButtonAction<FD>>>,
|
||||||
}
|
}
|
||||||
impl<FD: FormToolData> Default for ButtonData<FD> {
|
impl<FD: FormToolData> Default for ButtonData<FD> {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
|
|||||||
@ -4,8 +4,8 @@ use leptos::{Signal, View};
|
|||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Default)]
|
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Default)]
|
||||||
pub struct CheckboxData {
|
pub struct CheckboxData {
|
||||||
pub(crate) name: String,
|
pub name: String,
|
||||||
pub(crate) label: Option<String>,
|
pub label: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ControlData for CheckboxData {
|
impl ControlData for CheckboxData {
|
||||||
|
|||||||
@ -4,7 +4,7 @@ use leptos::View;
|
|||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Default)]
|
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Default)]
|
||||||
pub struct HeadingData {
|
pub struct HeadingData {
|
||||||
pub(crate) title: String,
|
pub title: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl VanityControlData for HeadingData {
|
impl VanityControlData for HeadingData {
|
||||||
|
|||||||
@ -4,9 +4,9 @@ use leptos::{Signal, View};
|
|||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Default)]
|
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Default)]
|
||||||
pub struct RadioButtonsData {
|
pub struct RadioButtonsData {
|
||||||
pub(crate) name: String,
|
pub name: String,
|
||||||
pub(crate) label: Option<String>,
|
pub label: Option<String>,
|
||||||
pub(crate) options: Vec<String>,
|
pub options: Vec<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ControlData for RadioButtonsData {
|
impl ControlData for RadioButtonsData {
|
||||||
|
|||||||
@ -4,12 +4,12 @@ use leptos::{Signal, View};
|
|||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Default)]
|
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Default)]
|
||||||
pub struct SelectData {
|
pub struct SelectData {
|
||||||
pub(crate) name: String,
|
pub name: String,
|
||||||
pub(crate) label: Option<String>,
|
pub label: Option<String>,
|
||||||
/// The options for the select.
|
/// The options for the select.
|
||||||
///
|
///
|
||||||
/// The first value is the string to display, the second is the value.
|
/// 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 {
|
impl ControlData for SelectData {
|
||||||
|
|||||||
@ -5,10 +5,10 @@ use std::ops::RangeInclusive;
|
|||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||||
pub struct SliderData {
|
pub struct SliderData {
|
||||||
pub(crate) name: String,
|
pub name: String,
|
||||||
pub(crate) label: Option<String>,
|
pub label: Option<String>,
|
||||||
pub(crate) min: i32,
|
pub min: i32,
|
||||||
pub(crate) max: i32,
|
pub max: i32,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for SliderData {
|
impl Default for SliderData {
|
||||||
|
|||||||
@ -4,7 +4,7 @@ use leptos::{prelude::Signal, View};
|
|||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Default)]
|
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Default)]
|
||||||
pub struct SpacerData {
|
pub struct SpacerData {
|
||||||
pub(crate) height: Option<String>,
|
pub height: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl VanityControlData for SpacerData {
|
impl VanityControlData for SpacerData {
|
||||||
|
|||||||
@ -5,11 +5,11 @@ use std::ops::RangeInclusive;
|
|||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Default)]
|
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Default)]
|
||||||
pub struct StepperData {
|
pub struct StepperData {
|
||||||
pub(crate) name: String,
|
pub name: String,
|
||||||
pub(crate) label: Option<String>,
|
pub label: Option<String>,
|
||||||
pub(crate) step: Option<i32>,
|
pub step: Option<i32>,
|
||||||
pub(crate) min: Option<i32>,
|
pub min: Option<i32>,
|
||||||
pub(crate) max: Option<i32>,
|
pub max: Option<i32>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ControlData for StepperData {
|
impl ControlData for StepperData {
|
||||||
|
|||||||
@ -4,7 +4,7 @@ use leptos::{prelude::Signal, View};
|
|||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Default)]
|
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Default)]
|
||||||
pub struct SubmitData {
|
pub struct SubmitData {
|
||||||
pub(crate) text: String,
|
pub text: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl VanityControlData for SubmitData {
|
impl VanityControlData for SubmitData {
|
||||||
|
|||||||
@ -4,8 +4,8 @@ use leptos::{Signal, View};
|
|||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Default)]
|
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Default)]
|
||||||
pub struct TextAreaData {
|
pub struct TextAreaData {
|
||||||
pub(crate) name: String,
|
pub name: String,
|
||||||
pub(crate) placeholder: Option<String>,
|
pub placeholder: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ControlData for TextAreaData {
|
impl ControlData for TextAreaData {
|
||||||
|
|||||||
@ -4,11 +4,11 @@ use leptos::{Signal, View};
|
|||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||||
pub struct TextInputData {
|
pub struct TextInputData {
|
||||||
pub(crate) name: String,
|
pub name: String,
|
||||||
pub(crate) placeholder: Option<String>,
|
pub placeholder: Option<String>,
|
||||||
pub(crate) label: Option<String>,
|
pub label: Option<String>,
|
||||||
pub(crate) initial_text: String,
|
pub initial_text: String,
|
||||||
pub(crate) input_type: &'static str,
|
pub input_type: &'static str,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for TextInputData {
|
impl Default for TextInputData {
|
||||||
|
|||||||
@ -221,6 +221,59 @@ impl<FD: FormToolData> FormBuilder<FD> {
|
|||||||
Box::new(value_setter)
|
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<ServFn>(
|
||||||
|
self,
|
||||||
|
action: Action<ServFn, Result<ServFn::Output, ServerFnError<ServFn::Error>>>,
|
||||||
|
fd: FD,
|
||||||
|
fs: FD::Style,
|
||||||
|
) -> Form<FD>
|
||||||
|
where
|
||||||
|
ServFn: DeserializeOwned + ServerFn<InputEncoding = PostUrl> + 'static,
|
||||||
|
<<ServFn::Client as Client<ServFn::Error>>::Request as ClientReq<ServFn::Error>>::FormData:
|
||||||
|
From<FormData>,
|
||||||
|
{
|
||||||
|
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! {
|
||||||
|
<ActionForm action=action on:submit=on_submit>
|
||||||
|
{elements}
|
||||||
|
</ActionForm>
|
||||||
|
};
|
||||||
|
|
||||||
|
Form {
|
||||||
|
fd,
|
||||||
|
validations: self.validations,
|
||||||
|
view,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub(crate) fn build_action_form<ServFn>(
|
pub(crate) fn build_action_form<ServFn>(
|
||||||
self,
|
self,
|
||||||
action: Action<ServFn, Result<ServFn::Output, ServerFnError<ServFn::Error>>>,
|
action: Action<ServFn, Result<ServFn::Output, ServerFnError<ServFn::Error>>>,
|
||||||
|
|||||||
Reference in New Issue
Block a user