Re: [Rails] Changing display text of submit button without changing value passed to controller

On Jul 7, 2014, at 9:15 AM, Ronald Fischer wrote:

> Please have a look at this form:
>
> <%= form_for @data, url: data_path do |f| %>
> ...
> <%= f.submit("accept", name:"judgement") %>
> <%= f.submit("reject", name:"judgement") %>
> <% end %>
>
> These buttons display "accept" and "reject". Clicking on the first
> button would pass
>
> "judgement" => "accept"
>
> to the application. This is exactly what I want, but I want to be able
> to change the text which is visible on the button (for example, when
> displaying the page in a different language).
>
> Can this be done?

Probably, through the i18n framework, but if you do that, you'll have to pass any recognition of the button value (in your controller) through the same framework. That's because the value will be changed, so judgement: [accept in another language] rather than accept.

You could possibly do this in JavaScript, such that your form submit behavior was to translate the language back when the button was clicked and before the form was sent to the server. Maybe something like this (leaving out the Rails generators at the moment):

<input type="submit" value="[accept in dutch]" data-value="accept">

// Prototype-flavored JavaScript
$('my_form').observe('submit', function(evt){
evt.stop();
this.select('input[data-value]').each(function(elm){
elm.setValue(elm.readAttribute('data-value'));
});
this.submit();
});

That should allow you to have the internationalized cake and eat it too.

Walter

>
> Ronald
>
> --
> Posted via http://www.ruby-forum.com/.
>
> --
> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
> To post to this group, send email to rubyonrails-talk@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/5e24e429be3356cc4cda3e666fc7fac2%40ruby-forum.com.
> For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/0712E6FF-2E8C-4034-9897-ADE4D45ACFB6%40wdstudio.com.
For more options, visit https://groups.google.com/d/optout.