Add id to ActionForm and MultiActionForm (#2535)

This commit is contained in:
Ben Wishovich 2024-04-16 14:52:51 -07:00 committed by GitHub
parent 6141e73436
commit c8186eea13
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 12 additions and 0 deletions

View File

@ -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>>,
@ -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| {
@ -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());
@ -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>,
@ -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());