From 374ec7055fb30d8ddbbc28a93f6c3f8b42b6544c Mon Sep 17 00:00:00 2001 From: Gabriel de Perthuis Date: Sun, 17 Sep 2023 14:36:46 +0200 Subject: [PATCH] Allow default values for absent server_fn arguments This allows form submission with checkbox inputs to work. For example: let doit = create_server_action::(); #[server(DoItSFn, "/api")] pub async fn doit(is_good: bool) -> Result<(), ServerFnError> {} Arguments absent in the request to the server API will use the Default::default() constructor. --- server_fn_macro/src/lib.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/server_fn_macro/src/lib.rs b/server_fn_macro/src/lib.rs index 4e0c6b7c91..f5b43e7f9a 100644 --- a/server_fn_macro/src/lib.rs +++ b/server_fn_macro/src/lib.rs @@ -110,7 +110,10 @@ pub fn server_macro_impl( } FnArg::Typed(t) => t, }; - quote! { pub #typed_arg } + quote! { + #[serde(default)] + pub #typed_arg + } }); let cx_arg = body.inputs.iter().next().and_then(|f| {