Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support default values for annotated server_fn arguments #1762

Merged
merged 1 commit into from
Sep 21, 2023

Conversation

g2p
Copy link
Contributor

@g2p g2p commented Sep 20, 2023

This allows form submission with checkbox inputs to work.
For example:

let doit = create_server_action::<DoItSFn>();
<ActionForm action=doit>
  <input type="checkbox" name="is_good" value="true"/>
  <input type="submit"/>
</ActionForm>

#[server(DoItSFn, "/api")]
pub async fn doit(#[server(default)] is_good: bool) -> Result<(), ServerFnError> {}

If is_good is absent in the request to the server API,
Default::default() is used instead.

This is the approach suggested by #1745 (comment)

This allows form submission with checkbox inputs to work.
For example:

    let doit = create_server_action::<DoItSFn>();
    <ActionForm action=doit>
      <input type="checkbox" name="is_good" value="true"/>
      <input type="submit"/>
    </ActionForm>

    #[server(DoItSFn, "/api")]
    pub async fn doit(#[server(default)] is_good: bool) -> Result<(), ServerFnError> {}

If is_good is absent in the request to the server API,
`Default::default()` is used instead.
@g2p g2p force-pushed the server_fn-attr-default branch from 39b0e93 to 3c2e9e0 Compare September 20, 2023 22:35
@gbj
Copy link
Collaborator

gbj commented Sep 21, 2023

Looks good, thanks! (Failing CI was due to my mistake on the main branch earlier, have tested locally and this works well.)

@gbj gbj merged commit 2c8f464 into leptos-rs:main Sep 21, 2023
54 of 55 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants