Rails submit button text (formtastic) - how to change label of submit button?
Asked Answered
A

2

10

I am using simple_form and the following code to create the button.

<%= form.action :submit, :value => "submit", :button_html => { :class => "lagoon" }  %>

However the button is (still) labeled 'Create User' instead of 'submit'. I thought setting the value => would do it but it didn't

Alannaalano answered 8/8, 2012 at 14:4 Comment(0)
F
21

Probably better and correct way is to use :label key and keep :button_html for styling

<%= form.action :submit, :label => "Submit", :button_html => { :class => "lagoon" } %>

I think best idea is to use I18n keys. Check Formtastic docs:

Formtastic decides which label to use in the following order:

  1. :label # :label => "Choose Title"
  2. Formtastic i18n # if either :label => true || i18n_lookups_by_default = true (see Internationalization)
  3. Activerecord i18n # if localization file found for the given attribute
  4. label_str_method # if nothing provided this defaults to :humanize but can be set to a custom method

https://github.com/justinfrench/formtastic

Freberg answered 20/1, 2013 at 0:2 Comment(0)
A
6

Turned out I need to do:

<%= form.action :submit, :button_html => { :value => 'Submit', :class => "lagoon" }  %>
Alannaalano answered 8/8, 2012 at 14:35 Comment(1)
This is the only thing that actually worked for me. Thanks!Selftaught

© 2022 - 2024 — McMap. All rights reserved.