Remove Button Styling From f.submit in Rails Form - css

I have a simple form that simply sets the #active attribute to true/false. Within the form there is only one single hidden_field. Here is how I currently have the submit button for the form looking when the #active status is true.
When clicked, the form will submit and change the #active attribute to false. When redisplayed it will look like this:
.
Basically the form functions as a toggle switch that behind the scenes submits a form which toggles an attribute to true/false.
It works wonderfully. However, I do not want any of the default button styling. I don't want that gray box or the border. Instead: I only want to show that font-awesome glyphicon for the button, and that is it.
Here is the code I currently have which displays the glyphicon with the gray button css:
<td>
<%= form_for blog do |f| %>
<% if blog.active %>
<%= f.hidden_field :active, value: false %>
<% else %>
<%= f.hidden_field :active, value: true %>
<% end %>
<% if blog.active? %>
<%= f.button do %>
<i class="fa fa-toggle-on fa-2x text-success" aria-hidden="true"></i>
<% end %>
<% else %>
<%= f.button do %>
<i class="fa fa-toggle-off fa-2x text-danger" aria-hidden="true"></i>
<% end %>
<% end %>
<% end %>
</td>
Question: How can I take the button styling off of the f.submit button and only have the glyphicon to represent the submit button?

Would love to hear if there is a better solution. Basically all I did was added a new css class which sets the background property to none and the border property to none.
<% if blog.active? %>
<%= f.button, class: 'remove-submit-btn-style' do %>
<i class="fa fa-toggle-on fa-2x text-success" aria-hidden="true"></i>
<% end %>
<% else %>
<%= f.button, class: 'remove-submit-btn-style' do %>
<i class="fa fa-toggle-off fa-2x text-danger" aria-hidden="true"></i>
<% end %>
<% end %>
And then in app/assets/stylesheets/application.scss
.remove-submit-btn-style {
background: none;
border: none;
}

Related

Rails | How to target Invalid Input fields with Tailwind

This is annoying because I feel like I have tried everything. My goal is to have a red ring around invalid input fields when the input is invalid. How do I target invalid input fields in rails 6. I am using a rails form which is generated by devise. I am also using tailwind css.
I have tried all of the following.
.invalid{
#apply ring-2 ring-red-700
}
.input:invalid{
#apply ring-2 ring-red-700
}
.input-group {
.invalid {
#apply ring-2 ring-red-700
}
}
Here is the form I am using to register users
<% content_for :devise_form do %>
<%= form_for(resource, as: resource_name, url: session_path(resource_name), :html => {:class => 'form-horizontal' }) do |f| %>
<div class="input-group">
<%= f.label :email %><br />
<%= f.email_field :email,
autofocus: true,
autocomplete: "email",
class: "input",
placeholder: "Your Email"%>
</div>
<div class="input-group">
<%= f.label :password %><br />
<%= f.password_field :password,
autocomplete: "current-password",
class: "input"%>
</div>
<% if devise_mapping.rememberable? %>
<div class="field">
<%= f.check_box :remember_me %>
<%= f.label :remember_me %>
</div>
<% end %>
<div class="input-group">
<%= f.submit "Log in", class: "btn btn-default loader" %>
</div>
<% end %>
<hr class="mt-6 border" />
<%= render "devise/shared/links" %>
<% end %>
<%= render "devise/shared/form_wrapper" %>
So how do I target fields whose input's are invalid?
I ended up using the developer tools in the browser. I inspected the element which is called input#user_password.invalid. So the long term solution is to use inspect elements.
#layer components {
.field_with_errors { #apply border-2 border-red-700}
}

How to assign a link to omniauth facebook button

This is the code I have:
<div class="col-md-6 col-sm-6 col-xs-6">
<%- if devise_mapping.omniauthable? %>
<%- resource_class.omniauth_providers.each do |provider| %>
<%= link_to "Sign in", omniauth_authorize_path(resource_name, provider) %>
<% end -%>
<% end -%>
</div>
From the code above how can I change link_to "Sign in" with:
<button class="btn btn-facebook btn btn-lg btn-block"><i class="fa fa-facebook fa-2x"></i> | Connect with <br> Facebook</button>
So instead of "sign in" simple button, I will show my custom made Facebook button.
Answer: this is how i solved it
<div class="col-md-6 col-sm-6 col-xs-6">
<%- if devise_mapping.omniauthable? %>
<%- resource_class.omniauth_providers.each do |provider| %>
<%= link_to omniauth_authorize_path(resource_name, provider), class: 'btn btn-facebook btn btn-lg btn-block' do %>
<i class="fa fa-facebook fa-2x"></i>
|Connect with <br> Facebook
<% end %>
<% end -%>
<% end -%>
</div>
and it looks like this
when someone clicks on that,it gets redirected to the required path,which is omniauth_authorize_path(resource_name, provider)
for those who need the css code for this button here it is
.btn-facebook.btn.btn-lg.btn-block {
color: white;
background-color: DodgerBlue;
font-size: 1em;
&:hover {
color: white;
background-color: RoyalBlue;
}
}
I would appreciate if someone,would tell me how to make the "f" icon,to be in the center of the button.
Thank you
What I did:
<%= link_to raw('<span class="fa fa-facebook"></span> Ingresa con Facebook'), user_omniauth_authorize_path(:facebook), :class => 'btn btn-block btn-social btn-facebook form-control' %>
Im using the bootstrap-social gem and the font-awesome gem to style it exactly like facebook looks :P
https://github.com/gavinkflam/bootstrap-social-rails

Change the size of a bootstrap button in a div

I am using bootstrap buttons in my code. I would like to change certain buttons in a particular div however. The should be smaller
<div class="well">
<div class="bookmark">
<% #bookmarks.each do |bookmark| %>
<p>
<%= link_to bookmark.url %>
#these should be smaller
<%= link_to "Edit bookmark", edit_topic_bookmark_path(#topic, bookmark), class: "btn btn-danger" %>
<%= link_to "Destroy bookmark", [#topic, bookmark], method: :delete, class: "btn btn-danger" %>
</p>
<%= render partial: 'favorites/favorite', locals: { favorite: #favorite, bookmark: #bookmark } %>
<% end %>
</div>
<%= link_to "New bookmark", new_topic_bookmark_path(#topic), class: 'btn btn-default' %>
</div>
I was trying do this adding this to my application.css.scss file
.bookmarks btn {
size: 2px;
}
But this does not seem to work. Any suggestions?
try this:
<p>
<%= link_to bookmark.url %>
#these should be smaller
<%= link_to "Edit bookmark", edit_topic_bookmark_path(#topic, bookmark), class: "btn btn-danger btn-sm" %>
<%= link_to "Destroy bookmark", [#topic, bookmark], method: :delete, class: "btn btn-danger btn-sm" %>
</p>
You could these classes for sizing buttons:
btn-lg
btn-sm
btn-xs
bootstrap documentation
Did you try the bootstrap button size classes?
You custom css for the button could be something like.
.custom-button {
font-size:0.8em;
padding:5px;
}
Where you lower the padding and font size to reduce the size.
I think the quick way is make it important
.bookmarks btn {
size: 2px!important;
}

Ruby on Rails--submitt button and page is as wide as web page

Following the ruby-on-rails tutorial by Micheal Hartl
I've gotten to the sign-up page layout part( 7.22, listing 7.19>> http://www.railstutorial.org/book/sign_up)
But the things is my page displays oddly, the submit button is as wide as the web page not to mention the whole form as well.
I checked the code and it is the same as the book states, the only difference is I changed "$grayLighter" to "$gray-light" as "$grayLighter" I believe is depreciated.
Here is my custom.css.scss
input, textarea, select, .uneditable-input {
border: 1px solid #bbb;
width: 100%;
margin-bottom: 15px;
#include box_sizing;
}
input {
height: auto !important;
}
Here is my
app/views/users/new.html.erb
<% provide(:title, 'Sign up') %>
<h1>Sign up</h1>
<div class="row">
<div class="span6 offset3">
<%= form_for(#user) do |f| %>
<%= f.label :name %>
<%= f.text_field :name %>
<%= f.label :email %>
<%= f.text_field :email %>
<%= f.label :password %>
<%= f.password_field :password %>
<%= f.label :password_confirmation, "Confirmation" %>
<%= f.password_field :password_confirmation %>
<%= f.submit "Create my account", class: "btn btn-large btn-primary" %>
<% end %>
</div>
</div>
One of the things I have run into recently is that the CSS is pulled in during the :precompile stage of the build. So when I make CSS changes, I have to remember to build the app, or bounce the host its on so it pulls in any CSS changes during the :precompile.
What I do to test is to put the CSS on the top of the html.erb page in brackets.
This allows me to test the CSS with a simple page refresh on my browser. Once I have that working and I know it looks good. Then I copy that CSS to the relevant CSS file and build it to test it again.
Not sure if this is your issue or not, but I know it messed with me.
In Bootstrap3, span6 offset3 doesn't work.
try this :
<% provide(:title, 'Sign up') %>
<h1>Sign up</h1>
<div class="row">
<div class="col-xs-12 col-sm-6 col-sm-offset-3">

How can I make the twitter-like hover 'Follow' button with bootstrap?

Now I have the button with which, I can follow user, or un-follow.
Now when the target user is already followed. it's shown just like this.
Then the target user is not followed, it's shown just like this.
I'd like it to be shown 'following' when the target user is already followed.
Then when I bring mouse cursor over the button, the display should be changed to 'Un-Follow'.
How can I do that with bootstrap?
view
<% if user_signed_in? %>
<% unless user == current_user %>
<% if current_user.following?(user) %>
<%= link_to(unfollow_user_path(user), :remote => true, :class => 'btn') do %>
<i class="icon-remove"></i>
Un-Follow
<% end %>
<% else %>
<%= link_to(follow_user_path(user) ,:remote => true, :class => 'btn btn-primary') do %>
<i class="icon-ok icon-white"></i>
Follow
<%end%>
<% end %>
<% end %>
<% else %>
<%= link_to(new_user_session_path , :class => 'btn btn-primary') do %>
<i class="icon-ok icon-white"></i>
Follow
<%end%>
<% end %>
HTML
<a href="/user/1/follow" class="btn btn-primary" data-remote="true">
<i class="icon-ok icon-white"></i>
Follow
</a>
<a href="/user/1/unfollow" class="btn btn-primary" data-remote="true">
<i class="icon-remove icon-white"></i>
Un-Follow
</a>
UPDATE:
<a href="/user/1/unfollow" class="btn" data-remote="true" onhover="someFunction()">
<i id="Following" class="icon-remove"></i>
Following
</a>
Using the onHover event You can use jQuery to change the "class" attribute of the button you want to change the text too.
i.e.
<a href="/user/1/follow" onHover="someFunction();" class="btn btn-primary" data-remote="true">
<i id="Following" class="icon-ok icon-white"></i>
Following
</a>
someFunction() {
$('i#Following').attr("class", "icon-ok icon-white").innerText("Unfollow");
}
you get the picture hopefully.
Edit:
This is the full code that should fire the code in someFunction on mouse over.
<html>
<head>
<script type="text/javascript">
function someFunction()
{
alert("Hello");
}
</script>
</head>
<body>
<a href="/user/1/unfollow" class="btn" data-remote="true" onmouseover="someFunction();return true;" >
<i id="Following" class="icon-remove"></i>
Following
</a>
</body>
</html>

Resources