How to Eliminate Styling on the Submit Button in a Rails Form

I've developed a simple form that changes the status of the #active attribute to true or false. The form includes only one hidden_field. Below is an example of how the submit button appears when the #active status is set to true.

https://i.sstatic.net/ORWiZ.png

Upon clicking, the form submits and switches the #active attribute to false. After submission, it will display as shown in this image:

https://i.sstatic.net/UIh7I.png.

In essence, the form serves as a toggle switch that automatically submits a form to alternate between true/false for a specific attribute.

The functionality is solid. However, I aim to remove all default styling that comes with the button. I want neither the gray box nor the border. Instead, my goal is to showcase solely the font-awesome glyphicon for the button.

Below is the current code snippet displaying the glyphicon along 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 strip away the button styling from the f.submit button and exclusively show the glyphicon as the representation for the submit button?

Answer №1

Is there a more efficient way to handle this issue? My approach involved creating a new css class that removes the background and border properties.

<% 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  %>

You can find the implementation in

app/assets/stylesheets/application.scss

.remove-submit-btn-style {
  background: none;
  border: none;
}

https://i.sstatic.net/PlSNp.png

https://i.sstatic.net/uTB8y.png

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Expanding sidebar height to match parent using Flexbox

Looking for the best way to adjust a child element to match the height of its parent? I've experimented with various techniques, but haven't had much success. I'm leaning towards using flexbox as it seems to be the latest trend. Here's ...

A stylish Bootstrap list group featuring large Font Awesome icons

I am working with a Bootstrap 5 List Group element on my webpage. To enhance its visual appeal, I want to include oversized Font Awesome icons. After some styling and using a span tag, I managed to add the icon successfully. However, the issue I am facing ...

The HTML element in the side menu is not adjusting its size to fit the parent content

Update: What a day! Forgot to save my work... Here is the functioning example. Thank you for any assistance. I have set up a demo here of the issue I'm facing. I am utilizing this menu as the foundation for a page I am developing. The menu is built ...

What are the steps to upgrade to Bootstrap 4 in Laravel 5.5?

I am looking to transition to Bootstrap 4 in Laravel 5.5, Previously, I ran: composer require laravelnews/laravel-twbs4 However, I encountered layout issues in my "auth view" so I tried this: php artisan preset bootstrap4-auth Unfortunately, the p ...

Having trouble with my custom dropdown selector conflicting with Bootstrap 4 CSS

After searching for an alternative to the typical dropdown selectors, I stumbled upon a neat custom version on W3schools. However, I encountered an issue where it clashes with bootstrap. Despite including select: hide; in the CSS, the original dropdown sel ...

What is the best way to position HTML grandchildren using CSS Grid Lines?

I am looking to use CSS grid to create a section divided into 3 areas: header (yellow), body (red), and controls (blue). Each area will have its own div as the grid item, with children elements within these divs. https://i.sstatic.net/A367O.png Is it pos ...

What is the best way to handle a 3-element mode using an onClick function in Next.js?

Creating an accordion menu in Next.js comes with the challenge of implementing 3 different modes for an element: The first mode is default, where no click event has occurred: .mainLi_default In the second mode, the first click event triggers the opening o ...

Is there a way to create unique animations for CSS drop down div

I've been attempting to implement a hover effect on my drop-down cart that makes it fade or slide up similar to submenus. But, CSS transitions are not my forte! I've tried using generic fades with the transition property, but no luck. Currently ...

Utilizing Bootstrap 4 for creating full-width inputs with input-group-prepend functionality

Below is the code snippet: <div class="col-md-8 content-row-top-spacer"> <div class="input-group"> <div class="input-group-prepend"><span class="input-group-text">Name</span></div> <%= f.text_field :name, ...

What is the best way to create a sticky/fixed navbar that conceals the div above it while scrolling on the page?

When I am at the top of the page, I want to display the phone number and email above the navigation bar. However, as soon as I start scrolling down, I want the phone number and email to disappear and only show the navigation bar. I have attempted using fix ...

The padding on this button seems to be arbitrary and nonsensical

I attempted to create a button with a red border that is positioned at the bottom and center, but the padding seems to be interfering with my design. It appears that with the border, the width extends to 100% which doesn't make sense. I have tried va ...

You cannot apply Contextual Classes to override Table Header Colors Classes like .thead-dark or .thead-light

I am currently learning about tables in Bootstrap 4. I am facing an issue where the background-color in the table-light class is not being applied. I suspect this might be due to the thead-dark class taking precedence over it. Could you please clarify why ...

What is the best way to arrange divs in varying order across different breakpoints?

I am currently utilizing Bootstrap and aiming to achieve a specific layout as shown below: https://i.sstatic.net/dZ4Tt.png The numbers are indicating the desired order of the divs in a single column on mobile devices. The HTML code I attempted is as foll ...

Images on web pages are automatically resized to fit into a smaller preview window

Currently, I am facing an issue with the display of images in my grid windows on my website . The images are appearing as partial representations instead of rescaled versions where the whole picture is resized to fit the grid window. I have attempted mod ...

How to Customize Bootstrap Colors Globally in Angular 4 Using Code

I am interested in developing a dynamic coloring system using Angular. I have set up a service with four predefined strings: success, info, warning, and danger, each assigned default color codes. My goal is to inject this service at the root of my applicat ...

How to iterate through all options in a dropdown menu and identify the selected value using Selenium WebDriver

Having a problem extracting all the available options in a drop-down list and then looping through to find the selected value. Ruby snippet provided below: dropdown = @@driver.find_element(:id, 'dropdown_7') all_options = dropdown.fi ...

Changing the line height causes the bullet position to shift downwards

Here is a bullet list: <ol className="graphkregular mt-2" style={{ display: "listItem" }}> <li> <small>{popupData.content[0].split("\n").join("\n")}< ...

What is the best way to showcase a category on the thumbnail of a WordPress post?

Hey everyone, I hope you're all having a great day! I need some assistance with a slider I'm creating on my WordPress site. I can't seem to figure out how to display the category of each post that appears in the slider and have it stand out. ...

Adjusting table font dynamically using Angular and CSS

I am currently working on an Angular project and facing a challenge with setting the font size dynamically in a table. I have created a function to address this issue, which includes the following code snippet: $('.td').css({ 'font-size ...

What is the best way to align the middle item of a flexbox using CSS?

I am attempting to present text divided into 3 divs - the middle div contains the highlighted portion of the text, while the first and last divs contain the text before and after the highlighted section. Both the first and last flex items have classes tha ...