All threads / Adding an inline style to a Datetime_select field in simple_form

Ask A Question

Notifications

You’re not receiving notifications from this thread.

Adding an inline style to a Datetime_select field in simple_form

Lee Sheppard asked in Rails

How do I add an inline style to a Datetime_select field in simple_form?
What I would like to have worked (this is in Slim):

= f.datetime_select :published_at, style="width:auto;"

but this isn't the case. It doesn't add the style. The app admin is managed through a gem and I don't want to modify the styling in that gem. So I'm trying to override the widths to correct their display by doing inline styling.

from the documentation :
datetime_select(object_name, method, options = {}, html_options = {})
in your case try this :
= f.datetime_select :published_at,{} ,{style="width:auto;"}

It seems that you can only apply classes and not inline styling to simple_form. Which is a shame if you need to have a hack in place.

I think that you can do it from the html_options = {}
ApiDock

Join the discussion

Want to stay up-to-date with Ruby on Rails?

Join 37,629+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.

    logo Created with Sketch.

    Ruby on Rails tutorials, guides, and screencasts for web developers learning Ruby, Rails, Javascript, Turbolinks, Stimulus.js, Vue.js, and more. Icons by Icons8

    © 2020 GoRails, LLC. All rights reserved.