Search code examples
htmlruby-on-railshamlsimple-form

Pre-fill field in Simple Form


How do I pre-fill a form field in Simple Form? I tried setting the default value, but still it wouldn't show up when the form loaded:

= simple_form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f|
  = f.error_notification
  .form-inputs
    = f.input :code_entered, label: 'Checklist Code', value: params[:q], input_html: {id: 'sign_up_code' }
  .form-actions
    = f.button :submit, "Sign up"

Setting params[:q] as a placeholder value works, however.


Solution

  • = f.input :code_entered, label: 'Checklist Code', input_html: {id: 'sign_up_code', value: params[:q] }