Issue
I've got a button in my Rails app, and would like to have it set to autofocus, so the user can just hit enter to move on when the page is loaded.
The code below is not working: the button is working but it is not set to autofocus.
<%= link_to new_flashcard_flashcard_test_path(@flashcard_deck.next_flashcard), :class => 'btn btn-primary', :autofocus => true do %>
<span class="glyphicon glyphicon-link"></span>
Next card
<% end %>
Generated HTML
<a autofocus="autofocus" class="btn btn-primary" href="/flashcards/1188/flashcard_tests/new">
<span class="glyphicon glyphicon-link"></span>
Next card
</a>
Solution
HTML5 attribute autofocus is just for input fields, like
<input autofocus/>
Please read about it at w3schools You can achieve the same with some Javascript (used jQuery for the example):
jQuery(document).ready(function(){
$('*[autofocus]').focus()
})
Answered By - Christian Rolle
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.