Skip to content

Commit

Permalink
Add id to ActionForm and MultiActionForm (#2535)
Browse files Browse the repository at this point in the history
  • Loading branch information
benwis authored Apr 16, 2024
1 parent 6141e73 commit c8186ee
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions router/src/components/form.rs
Original file line number Diff line number Diff line change
Expand Up @@ -444,9 +444,13 @@ pub fn ActionForm<ServFn>(
ServFn,
Result<ServFn::Output, ServerFnError<ServFn::Error>>,
>,
/// Sets the `id` attribute on the underlying `<form>` tag
#[prop(optional, into)]
id: Option<AttributeValue>,
/// Sets the `class` attribute on the underlying `<form>` tag, making it easier to style.
#[prop(optional, into)]
class: Option<AttributeValue>,

/// A [`NodeRef`] in which the `<form>` element should be stored.
#[prop(optional)]
node_ref: Option<NodeRef<html::Form>>,
Expand Down Expand Up @@ -481,6 +485,7 @@ where
let value = action.value();

let class = class.map(|bx| bx.into_attribute_boxed());
let id = id.map(|bx| bx.into_attribute_boxed());

let on_submit = {
move |ev: SubmitEvent| {
Expand Down Expand Up @@ -524,6 +529,7 @@ where
let mut action_form = form()
.attr("action", action_url)
.attr("method", "post")
.attr("id", id)
.attr("class", class)
.on(ev::submit, on_submit)
.child(children());
Expand All @@ -549,6 +555,9 @@ pub fn MultiActionForm<ServFn>(
/// by default using [create_server_action](leptos_server::create_server_action) or added
/// manually using [leptos_server::Action::using_server_fn].
action: MultiAction<ServFn, Result<ServFn::Output, ServerFnError>>,
/// Sets the `id` attribute on the underlying `<form>` tag
#[prop(optional, into)]
id: Option<AttributeValue>,
/// Sets the `class` attribute on the underlying `<form>` tag, making it easier to style.
#[prop(optional, into)]
class: Option<AttributeValue>,
Expand Down Expand Up @@ -610,9 +619,12 @@ where
};

let class = class.map(|bx| bx.into_attribute_boxed());

let id = id.map(|bx| bx.into_attribute_boxed());
let mut action_form = form()
.attr("action", action_url)
.attr("method", "post")
.attr("id", id)
.attr("class", class)
.on(ev::submit, on_submit)
.child(children());
Expand Down

0 comments on commit c8186ee

Please sign in to comment.