use super::{ BuilderCxFn, BuilderFn, ControlRenderData, GetterVanityControlData, VanityControlBuilder, VanityControlData, }; use crate::{form::FormToolData, form_builder::FormBuilder, styles::FormStyle}; use leptos::{Signal, View}; use std::rc::Rc; /// Data used for the hidden control. #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Default)] pub struct HiddenData { pub name: String, } impl VanityControlData for HiddenData { fn build_control( fs: &FS, control: Rc>, value_getter: Option>, ) -> View { fs.hidden(control, value_getter) } } impl GetterVanityControlData for HiddenData {} impl FormBuilder { /// Builds a hidden form control and adds it to the form. /// /// This will be an input in the html form allowing you to insert some /// data the you might not want the user modifying. pub fn hidden(self, builder: impl BuilderFn>) -> Self { self.new_vanity(builder) } /// Builds a hidden form control using the form's context and adds it to /// the form. /// /// This will be an input in the html form allowing you to insert some /// data the you might not want the user modifying. pub fn hidden_cx( self, builder: impl BuilderCxFn, FD::Context>, ) -> Self { self.new_vanity_cx(builder) } } impl VanityControlBuilder { /// Sets the name of the hidden control. /// /// This is used for the html element's "name" attribute. /// In forms, the name attribute is the key that the data is sent /// with. pub fn named(mut self, control_name: impl ToString) -> Self { self.data.name = control_name.to_string(); self } }