Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

rails button_to :disabled => true still displays the button

I would like to display a button but in a disabled state,to show the user that they already saved an item.

I currently used something like:

<%= button_to 'Save', :disabled => item.is_saved? %>

The generated html looks like:

<form class="button-to" action="/results/save_item/748?class=buttons&amp;disabled=true" method="post"> 

<div><input type="submit" value="Save">
<input type="hidden" value="+TKyrnA9idfmCkwDycLjHIkSLNou6NMt8R4TI73RezU=" name="authenticity_token">
</div>
</form>

This disables the action by setting the disabled=true option. However, the button is still displayed. Is there a way to show the button in a disabled state if the condition is true?

thanks

like image 769
truthSeekr Avatar asked Feb 12 '10 23:02

truthSeekr


People also ask

Do screen readers skip disabled buttons?

By using the tabulator key and navigating within a form the screen readers will ignore the existence of any disabled button. Now close your eyes and imagine the screen reader reads out all the inputs of a form. You know you're within a form. And normally a form gets submitted by hitting a button.

Do screen readers read disabled buttons?

Sometimes disabled buttons are designed in a way that they cannot be read by a screen reader (buttons are not focusable, and hence users can't reach them with a keyboard).


2 Answers

You have to specify URL first or let it empty. In your case :disabled is a param[:disabled].

<%= button_to 'Save', {}, :disabled => item.is_saved? %>
like image 93
CLer Avatar answered Sep 19 '22 12:09

CLer


<% if item.is_saved? %>
  <%= button_to 'Save' %>
<% end %>
like image 41
Joshua Partogi Avatar answered Sep 20 '22 12:09

Joshua Partogi