pub struct FormBuilder<'a> { /* private fields */ }Expand description
Builder for constructing HTML forms
§Examples
use acton_htmx::forms::{FormBuilder, InputType};
let html = FormBuilder::new("/login", "POST")
.id("login-form")
.csrf_token("abc123")
.field("email", InputType::Email)
.label("Email Address")
.required()
.placeholder("you@example.com")
.done()
.field("password", InputType::Password)
.label("Password")
.required()
.done()
.submit("Sign In")
.build();Implementations§
Source§impl<'a> FormBuilder<'a>
impl<'a> FormBuilder<'a>
Sourcepub fn new(action: impl Into<String>, method: impl Into<String>) -> Self
pub fn new(action: impl Into<String>, method: impl Into<String>) -> Self
Create a new form builder with action and method
Sourcepub fn csrf_token(self, token: impl Into<String>) -> Self
pub fn csrf_token(self, token: impl Into<String>) -> Self
Set the CSRF token
Sourcepub fn enctype(self, enctype: impl Into<String>) -> Self
pub fn enctype(self, enctype: impl Into<String>) -> Self
Set the form enctype (for file uploads use “multipart/form-data”)
Sourcepub const fn errors(self, errors: &'a ValidationErrors) -> Self
pub const fn errors(self, errors: &'a ValidationErrors) -> Self
Set validation errors to display
Sourcepub fn submit_class(self, class: impl Into<String>) -> Self
pub fn submit_class(self, class: impl Into<String>) -> Self
Set the submit button CSS class
Sourcepub const fn novalidate(self) -> Self
pub const fn novalidate(self) -> Self
Disable browser validation (add novalidate attribute)
Sourcepub fn attr(self, name: impl Into<String>, value: impl Into<String>) -> Self
pub fn attr(self, name: impl Into<String>, value: impl Into<String>) -> Self
Add a custom attribute
Sourcepub fn htmx_delete(self, url: impl Into<String>) -> Self
pub fn htmx_delete(self, url: impl Into<String>) -> Self
Set hx-delete attribute
Sourcepub fn htmx_patch(self, url: impl Into<String>) -> Self
pub fn htmx_patch(self, url: impl Into<String>) -> Self
Set hx-patch attribute
Sourcepub fn htmx_target(self, selector: impl Into<String>) -> Self
pub fn htmx_target(self, selector: impl Into<String>) -> Self
Set hx-target attribute
Sourcepub fn htmx_trigger(self, trigger: impl Into<String>) -> Self
pub fn htmx_trigger(self, trigger: impl Into<String>) -> Self
Set hx-trigger attribute
Sourcepub fn htmx_indicator(self, selector: impl Into<String>) -> Self
pub fn htmx_indicator(self, selector: impl Into<String>) -> Self
Set hx-indicator attribute
Sourcepub fn htmx_push_url(self, url: impl Into<String>) -> Self
pub fn htmx_push_url(self, url: impl Into<String>) -> Self
Set hx-push-url attribute
Sourcepub fn htmx_confirm(self, message: impl Into<String>) -> Self
pub fn htmx_confirm(self, message: impl Into<String>) -> Self
Set hx-confirm attribute
Sourcepub fn htmx_disabled_elt(self, selector: impl Into<String>) -> Self
pub fn htmx_disabled_elt(self, selector: impl Into<String>) -> Self
Set hx-disabled-elt attribute
Sourcepub const fn htmx_validate(self) -> Self
pub const fn htmx_validate(self) -> Self
Enable hx-validate
Sourcepub fn field(
self,
name: impl Into<String>,
input_type: InputType,
) -> FieldBuilder<'a>
pub fn field( self, name: impl Into<String>, input_type: InputType, ) -> FieldBuilder<'a>
Add an input field and return a field builder
Sourcepub fn file(self, name: impl Into<String>) -> FileFieldBuilder<'a>
pub fn file(self, name: impl Into<String>) -> FileFieldBuilder<'a>
Add a file upload field and return a file field builder
This automatically sets the form enctype to multipart/form-data.
§Examples
use acton_htmx::forms::FormBuilder;
let form = FormBuilder::new("/upload", "POST")
.file("avatar")
.label("Profile Picture")
.accept("image/png,image/jpeg")
.max_size_mb(5)
.required()
.done()
.build();Sourcepub fn textarea(self, name: impl Into<String>) -> TextareaBuilder<'a>
pub fn textarea(self, name: impl Into<String>) -> TextareaBuilder<'a>
Add a textarea field and return a field builder
Sourcepub fn select(self, name: impl Into<String>) -> SelectBuilder<'a>
pub fn select(self, name: impl Into<String>) -> SelectBuilder<'a>
Add a select field and return a select builder
Sourcepub fn checkbox(self, name: impl Into<String>) -> CheckboxBuilder<'a>
pub fn checkbox(self, name: impl Into<String>) -> CheckboxBuilder<'a>
Add a checkbox field and return a checkbox builder
Add a hidden field
Sourcepub fn build(self) -> String
pub fn build(self) -> String
Build the form HTML using programmatic rendering
This uses the built-in programmatic renderer. For template-based
rendering that allows customization, use [build_with_templates].
Sourcepub fn build_with_templates(
self,
templates: &FrameworkTemplates,
) -> Result<String, FormRenderError>
pub fn build_with_templates( self, templates: &FrameworkTemplates, ) -> Result<String, FormRenderError>
Build the form HTML using template-based rendering
This uses minijinja templates from the XDG template directory, allowing users to customize the HTML structure.
§Errors
Returns error if template rendering fails.
§Example
use acton_htmx::forms::{FormBuilder, InputType};
use acton_htmx::template::framework::FrameworkTemplates;
let templates = FrameworkTemplates::new()?;
let html = FormBuilder::new("/login", "POST")
.field("email", InputType::Email)
.label("Email")
.done()
.build_with_templates(&templates)?;Sourcepub fn build_with_templates_and_options(
self,
templates: &FrameworkTemplates,
options: FormRenderOptions,
) -> Result<String, FormRenderError>
pub fn build_with_templates_and_options( self, templates: &FrameworkTemplates, options: FormRenderOptions, ) -> Result<String, FormRenderError>
Build the form HTML using template-based rendering with custom options
§Errors
Returns error if template rendering fails.
Trait Implementations§
Source§impl<'a> Clone for FormBuilder<'a>
impl<'a> Clone for FormBuilder<'a>
Source§fn clone(&self) -> FormBuilder<'a>
fn clone(&self) -> FormBuilder<'a>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl<'a> Freeze for FormBuilder<'a>
impl<'a> RefUnwindSafe for FormBuilder<'a>
impl<'a> Send for FormBuilder<'a>
impl<'a> Sync for FormBuilder<'a>
impl<'a> Unpin for FormBuilder<'a>
impl<'a> UnwindSafe for FormBuilder<'a>
Blanket Implementations§
Source§impl<T> ActonMessage for T
impl<T> ActonMessage for T
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Paint for Twhere
T: ?Sized,
impl<T> Paint for Twhere
T: ?Sized,
Source§fn fg(&self, value: Color) -> Painted<&T>
fn fg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the foreground set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like red() and
green(), which have the same functionality but are
pithier.
§Example
Set foreground color to white using fg():
use yansi::{Paint, Color};
painted.fg(Color::White);Set foreground color to white using white().
use yansi::Paint;
painted.white();Source§fn bright_black(&self) -> Painted<&T>
fn bright_black(&self) -> Painted<&T>
Source§fn bright_red(&self) -> Painted<&T>
fn bright_red(&self) -> Painted<&T>
Source§fn bright_green(&self) -> Painted<&T>
fn bright_green(&self) -> Painted<&T>
Source§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
Source§fn bright_blue(&self) -> Painted<&T>
fn bright_blue(&self) -> Painted<&T>
Source§fn bright_magenta(&self) -> Painted<&T>
fn bright_magenta(&self) -> Painted<&T>
Source§fn bright_cyan(&self) -> Painted<&T>
fn bright_cyan(&self) -> Painted<&T>
Source§fn bright_white(&self) -> Painted<&T>
fn bright_white(&self) -> Painted<&T>
Source§fn bg(&self, value: Color) -> Painted<&T>
fn bg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the background set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like on_red() and
on_green(), which have the same functionality but
are pithier.
§Example
Set background color to red using fg():
use yansi::{Paint, Color};
painted.bg(Color::Red);Set background color to red using on_red().
use yansi::Paint;
painted.on_red();Source§fn on_primary(&self) -> Painted<&T>
fn on_primary(&self) -> Painted<&T>
Source§fn on_magenta(&self) -> Painted<&T>
fn on_magenta(&self) -> Painted<&T>
Source§fn on_bright_black(&self) -> Painted<&T>
fn on_bright_black(&self) -> Painted<&T>
Source§fn on_bright_red(&self) -> Painted<&T>
fn on_bright_red(&self) -> Painted<&T>
Source§fn on_bright_green(&self) -> Painted<&T>
fn on_bright_green(&self) -> Painted<&T>
Source§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
Source§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
Source§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
Source§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
Source§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
Source§fn attr(&self, value: Attribute) -> Painted<&T>
fn attr(&self, value: Attribute) -> Painted<&T>
Enables the styling Attribute value.
This method should be used rarely. Instead, prefer to use
attribute-specific builder methods like bold() and
underline(), which have the same functionality
but are pithier.
§Example
Make text bold using attr():
use yansi::{Paint, Attribute};
painted.attr(Attribute::Bold);Make text bold using using bold().
use yansi::Paint;
painted.bold();Source§fn rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
Source§fn quirk(&self, value: Quirk) -> Painted<&T>
fn quirk(&self, value: Quirk) -> Painted<&T>
Enables the yansi Quirk value.
This method should be used rarely. Instead, prefer to use quirk-specific
builder methods like mask() and
wrap(), which have the same functionality but are
pithier.
§Example
Enable wrapping using .quirk():
use yansi::{Paint, Quirk};
painted.quirk(Quirk::Wrap);Enable wrapping using wrap().
use yansi::Paint;
painted.wrap();Source§fn clear(&self) -> Painted<&T>
👎Deprecated since 1.0.1: renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
fn clear(&self) -> Painted<&T>
resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.Source§fn whenever(&self, value: Condition) -> Painted<&T>
fn whenever(&self, value: Condition) -> Painted<&T>
Conditionally enable styling based on whether the Condition value
applies. Replaces any previous condition.
See the crate level docs for more details.
§Example
Enable styling painted only when both stdout and stderr are TTYs:
use yansi::{Paint, Condition};
painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);