Adding a default value to text-input in simple-form

45,190

Solution 1

<%= f.input :user, :input_html => { :value => '[email protected]' } %>

Solution 2

You can simply do:

<% f.text_field, value: '[email protected]' %>

text_field is good if you are working with form search gem like Ransack.

Solution 3

On rails 5.1 placeholder: 'aaaaaaaaaaa' works. E.g.

<%= f.input :user, :placeholder => '[email protected]' %>

will work on rails 5.1

Solution 4

You can try this option:

<%= f.input :user, label: '[email protected]' %>
Share:
45,190
Mark
Author by

Mark

Updated on December 04, 2020

Comments

  • Mark
    Mark over 3 years

    I want to add a default value to a text-input field using simple-form. With :placeholder it is not used as default....

    <%= f.input :user, :placeholder => '[email protected]' %>
    
    • mmike
      mmike almost 8 years
      to have default value and also keep actual value in field (for example user's email) try like this --- f.input :user, input_html: { value: @user.email.present? ? @user.email : '[email protected]' }. Also its new more readable syntax in RoR
  • Sergey Kishenin
    Sergey Kishenin almost 12 years
    Maybe, :input_html => { :value => '[email protected]' }
  • pgrosslicht
    pgrosslicht almost 12 years
    Yes, realized that too. Fixed it.
  • Gareth Jones
    Gareth Jones over 10 years
    I think if you do not use the :input_html option and simply use :value or value: then that value will be reset to the default each time you return to the edit page.