Search code examples
ruby-on-railsrubystringinputsimple-form

Change default size of text input in Simple Form


How can I change default size of SimpleForm inputs using initializer? I would like to treat as string all text fields too by default. So I want an input to have text size only when explicitly setting it as: :text. Is it even possible?


Solution

  • Yes, it's quite simple to do, I do not think it has to be done in an initializer but you would create a custom input with simpleform and create the method

    # app/inputs/text_input.rb
    class TextInput < SimpleForm::Inputs::Base
      def input_html_classes
        super.push('my-text-class')
      end
    end
    

    Then add the css rules in your application.css for .my-text-class { font-size: 48px; }