Is it possible to apply styles to the options in a grouped_collection_select in Rails?

I am currently utilizing Twitter Bootstrap and Ruby on Rails as the backend for my project.

Despite extensive research, I have been unable to find a solution to my current issue.

Within my web application, I am looking to implement dependent dropdowns (such as selecting a country and then a state). To achieve this, I have utilized the "grouped_collection_select" method. However, the options within the dropdown are dynamically generated and now I am in need of applying styling to these options such as border images, divider images, etc. Is it possible to style these options in such a manner? If not, is there an alternative solution available?

Thank you in advance for any assistance provided!

Answer №1

Absolutely possible!

 <div class="element">
  <%= f.label 'example' %>
  <%= f.grouped_collection_select :category_id, Category.roots.order(:name), :children, :name, :id, :name, {surround: true}, {class: "custom-select"} %> 
</div>

Curly braces must enclose the 'surround' parameter or it won't function properly. Changing the class from element to custom-select will cause it to fail as well. There are numerous other scenarios where it may not work, but I only tested these ones :)

Enjoy experimenting!

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

Despite following all the correct steps, the tailwind CLI remains unresponsive. Additionally, the default button fails to display any content

view the document and my packages (image) Although it worked with the cdn, I'm puzzled why I can't use it properly with the cli ...

Receive live notifications using the Cramp framework in Ruby and Server-Sent Events in HTML5

I have created a demo application to receive real-time updates from the server using Cramp(Ruby) and SSE(HTML5). Encountering the following errors while trying to access the HTML file at http://localhost/sse_time.html: Errors: Chrome: Uncaught Error: S ...

The text size in Google Chrome always stays consistent across the page

Encountered a puzzling issue with a website today involving unusual behavior in Google Chrome. Despite using the "CTRL +" and "CTRL -" functions to adjust text size, the images enlarge while the text size remains the same. I have thoroughly checked the HTM ...

"Requesting data with Ajax results in an undefined value

As a beginner in Rails, I'm feeling overwhelmed by an error I can't seem to fix. The issue arises when I attempt to invoke the get_info_from_iclass method located in my rentals_controller from my JavaScript file. $('document').read ...

Hidden Password Field Option in HTML

My HTML password textbox has the input type set as password, but I can still see what is being typed. This shouldn't happen as password inputs should be masked. Can someone please advise me on how to resolve this issue? To replicate, copy the code be ...

Form Validation Issues Detected

Could someone help explain why the code below is causing an error according to W3C guidelines: <form id="" method="post" action="" /> <input type="text" name="" title="" tabindex="10" class="" /> <inp ...

Best practices for hardcoding Ruby hashes

Currently, I'm immersing myself in the world of Ruby programming best practices, and stumbled upon this informative page: https://github.com/styleguide/ruby One interesting section within discusses "Hashes" and provides examples like: # Avoid this u ...

How can I arrange the "elements" within a bootstrap container?

Check out the code display here: Here's what I aim for it to show The alignment of the elements has been a real challenge for me. I just can't seem to get the "Gender:", "Gender RadioButton list", "Age:", "Age RadioButton list" to appear in 4 c ...

Bootstrap Modal is experiencing issues with its auto-complete feature

Our website utilizes a bootstrap modal, and we are currently working on implementing autocomplete functionality. The issue is that it's not functioning properly within the modal itself. Below is the code snippet: $( "#emp_id" ).autocomplete({ ...

Customize the color of the horizontal line in React using dynamic properties

Is there a way to customize the color of an <hr /> element in a React application? If we were to use a functional component to accomplish this, how would we go about it? ...

Exploring ways to locate the XPATH of an element within a div using Python and Selenium

I possess a piece of python code that necessitates the ability to traverse through divs and extract text content from each div accordingly. The structure of my program incorporates a loop, as demonstrated below: for i in range(friends_count): found = ...

Setting up JSP on a J2EE server using Eclipse

I'm encountering a specific issue with my setup. I am attempting to run JSP on a J2EE preview server within a Dynamic Web Project in Eclipse. While I know that it is possible to make it work by converting to a Maven project, adding dependencies, or us ...

Encountering an Issue on Heroku with Node.js - Error R10 (Boot timeout) -> The web process was unable to connect to

When trying to deploy my website on Heroku, I encountered the following error message: Application error An error occurred in the application and the page could not be served. As the application owner, I checked the logs for details as suggested by Herok ...

Guide on importing a custom CSS file from Syncfusion Theme Studio into an Angular project

Is there a way to incorporate custom scss files downloaded from Syncfusion Theme Studio into Angular CLI without adding the URL to the styles section in angular.json? Can we directly import it into styles.scss instead? I attempted to do so by including th ...

Is this an effective and appropriate method for establishing media queries?

<link id ="style" rel="stylesheet" type="text/css" title="other" href="regularStyles.css" /> <link rel="stylesheet" media= "all and (mid-width: 767px) and (max-width:2049px) and (min-height:767px) and (max-height: 1538px)" href="notePads.css" /& ...

Dynamic video autoplay with a hover effect using Bootstrap 3

I am looking to create a hovering effect on an autoloop video similar to what is seen on this website - This specific section of the website demonstrates the effect I am trying to achieve. Prior to hovering, the autoloop video has an overlay displayed on ...

How to place a child <div> within a parent <div> that is fixed on the page

I am currently working on creating a modal window using HTML/CSS. My goal is to have the modal window fixed in position relative to the browser window, with a white background. Inside the modal, there will be an image at the top and a div element at the bo ...

Selecting text within a parent div using JQuery

I have the following elements in my HTML: <div class ="parent"> <div class="inner">Hello <div>Goodbye</div> </div> </div> <div class ="parent"> <div class="inner">Hello <div>Goodbye</ ...

Color of selected Bootstrap radio toggle buttons

Can anyone help me figure out how to customize the colors of radio toggle buttons using my style.css in Bootstrap? I've managed to change the background color in normal mode, but I'm struggling with changing the checked state. I've searched ...

Turning On and Off Hover Effects in AngularJS

I am looking to implement a feature that enables and disables the hover state on an element based on certain conditions. As a newcomer to Angular, I am unsure of how to approach this and haven't been able to find a solution online. Here is a sample o ...