Skip to content

Allow form and button attributes in helper methods#111

Merged
RenzoMinelli merged 9 commits intomasterfrom
rm/use-attributes-hash-instead-of-classes
Mar 3, 2026
Merged

Allow form and button attributes in helper methods#111
RenzoMinelli merged 9 commits intomasterfrom
rm/use-attributes-hash-instead-of-classes

Conversation

@RenzoMinelli
Copy link
Copy Markdown
Contributor

What?

Allow form and button attributes in helper methods

Why?

Currently there's no easy way to set data attributes on these forms/buttons. So in this PR I propose we change these helper methods to accept a hash of attributes and simply delegate them to view helpers

Comment thread lib/devise/webauthn/helpers/credentials_helper.rb Outdated
Comment thread .tool-versions Outdated
@RenzoMinelli RenzoMinelli force-pushed the rm/use-attributes-hash-instead-of-classes branch from 3666c41 to 89bca3a Compare February 10, 2026 17:35
Comment on lines +6 to +10
def passkey_creation_form_for(resource_or_resource_name, html_options: {}, &block)
form_with(
url: passkeys_path(resource_or_resource_name),
method: :post,
class: form_classes
**html_options
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we could just do:

def passkey_creation_form_for(resource_or_resource_name, **options, &block)
  form_with(
    **options.merge(url: passkeys_path(resource_or_resource_name), method: :post)
  ) do |f|

which would allow users of this gem to use or helpers pretty much like Rails' form helpers:

passkey_creation_form_for(:user, class: "my-form", data: { turbo: false })

What do you think?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

interesting idea, yeah that sounds good.

@RenzoMinelli RenzoMinelli force-pushed the rm/use-attributes-hash-instead-of-classes branch from 4e44a76 to d621332 Compare March 3, 2026 14:33
Comment thread CHANGELOG.md Outdated

- Options for getting or creating passkeys and security keys are now served by dedicated Rails controllers and retrieved via JavaScript fetch requests. [#73](https://github.com/cedarcode/devise-webauthn/pull/73) [@nicolastemciuc]
- BREAKING!: Remove helpers for generating WebAuthn options. [#106](https://github.com/cedarcode/devise-webauthn/pull/115) [@nicolastemciuc]
- BREAKING: Replace `form_classes:` keyword argument with direct keyword arguments in all form helper methods (`passkey_creation_form_for`, `login_with_passkey_form_for`, `security_key_creation_form_for`, `login_with_security_key_form_for`). All options are delegated to `form_with`, allowing you to pass any HTML attributes or form options directly. [@RenzoMinelli]
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: we are using BREAKING!: (with a bang !) instead of BREAKING 🙂

Just for sake of consistency

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added in 370aa7b

@RenzoMinelli RenzoMinelli force-pushed the rm/use-attributes-hash-instead-of-classes branch from d621332 to 18c55ab Compare March 3, 2026 21:25
@RenzoMinelli RenzoMinelli merged commit 3804dc8 into master Mar 3, 2026
25 checks passed
@RenzoMinelli RenzoMinelli deleted the rm/use-attributes-hash-instead-of-classes branch March 3, 2026 21:34
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