leptos-rs / leptos

Build fast web applications with Rust.
https://leptos.dev
MIT License
15.84k stars 623 forks source link

Server function param custom name #2844

Closed BrandonDyer64 closed 1 week ago

BrandonDyer64 commented 3 weeks ago

Is your feature request related to a problem? Please describe. Cloudflare Turnstile (CAPTCHA) injects a form <input> that has the name cf-turnstile-response which isn't a valid rust ident. When using the <ActionForm/> (important for progressive degradation) I would need to do this, which obviously isn't possible:

#[server]
async fn signup(username: String, email: String, cf-turnstile-response: String) -> Result<_, _> {}

Describe the solution you'd like A serialization rename attribute for server function params.

#[server]
async fn signup(
    username: String,
    email: String,
    #[server(rename = "cf-turnstile-response")]
    cf_turnstile_response: String,
) -> Result<_, _> {}

Describe alternatives you've considered I'm realizing now that there is a data-response-field-name attribute that will override the form param name on the client side, so I'm unblocked on this. However, I still think this would be a useful feature for those times when it isn't possible.

rakshith-ravi commented 3 weeks ago

I think I should be able to take this up. Want to add a #[doc = "..."] attribute as well for the missing_docs lint