marick
Logout buttons for Bootstrap or Bulma <nav> elements
I can’t get a Logout button (or plain link) to look good in either a Bootstrap or Bulma navbar. My general question is: how do you make a <form> that wraps an <a class="button"...>...</a> render the same as the <a> alone?
Per the Phoenix book, logging out is done with:
link("Log out", to: session_path(conn, :delete, current_user)
… producing something like:
<form action="/sessions/4" class="link" method="post">
<input name="_method" type="hidden" value="delete">
<input name="_csrf_token" type="hidden" value="JBxGTxkhJX09aUM+IjEVNwQHFF8jEAAAbPi+AtgRE+5sMuDRLfFmjg==">
<a data-submit="parent" href="#" rel="nofollow">
Log out</a>
</form>
I can’t figure out how to wrap this or adorn it with class= such that it works across devices.
For example, I can get Logout to look right with Bootstrap in a wide window, but I get a misaligned entry in a phone-sized window:
In Bulma, which seems pretty nice, the result of:
<span class="nav-item">
<form action="/sessions/4" method="post">
<input name="_method" type="hidden" value="delete">
<input name="_csrf_token" type="hidden" value="JBxGTxkhJX09aUM+IjEVNwQHFF8jEAAAbPi+AtgRE+5sMuDRLfFmjg==">
<a class="button" data-submit="parent" href="#" rel="nofollow">
Log out
</a>
</form>
<a class="button is-info">
Sign up
</a>
</span>
… is buttons with no space between them in wide view:
… whereas two plain <a class="button"...> tags have a nice gap between them. (There’s a different problem in layout view.)
I’m getting too close to giving up on any server-side rendering and doing everything in Elm on the client side. Save me from myself!
Most Liked
dsissitka
Did you know that you can customize the form? For example, this:
<%= link("Delete",
class: "btn btn-danger btn-xs",
data: [confirm: "Are you sure?"],
form: [foo: "bar"],
method: :delete,
to: match_path(@conn, :delete, match)
) %>
Produces this:
<form action="/matches/272" class="link" foo="bar" method="post">
<input name="_method" value="delete" type="hidden">
<input name="_csrf_token" value="NTBAERxxSicQAWcQEnQKMQRdNx4GAAAAsv5csE/fCpUdeMbekrrK1w==" type="hidden">
<a class="btn btn-danger btn-xs" data-confirm="Are you sure?" data-submit="parent" href="#" rel="nofollow">Delete</a>
</form>
dsissitka
Re Bootstrap, what does your HTML look like?
Re Bulma, there is no space between the buttons because the rule that adds it expects .nav-item .button + .button:
.nav-item .button + .button {
margin-left: 10px;
}
Something like this should work:
<a class="button is-info" style="margin-left: 10px;">Sign up</a>
slashdotdash
This may not help you in this scenario, but I discovered yesterday that you can supply a block to the link helper function. This allows you to provide any HTML within the generated form and link element.
<%= if @current_user do %>
<span class="nav-item">
<%= link to: auth_path(@conn, :delete), method: :delete, class: "button" do %>
Log out
<% end %>
</span>
<% end %>
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #elixirconf-us
- #advent-of-code
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #hex











