Skip to content

Commit

Permalink
Always autofocus the _first_ field
Browse files Browse the repository at this point in the history
  • Loading branch information
pikesley committed Feb 20, 2016
1 parent c1d7047 commit f6f6782
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion app/views/shared/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@
<%= f.label :datetime, 'Date and time' %><br>
<%= f.text_field :datetime, class: 'form-control datetime' %>
</div>
<% count = 0 %>
<% autofocus = true %>
<% @metric.class.fields.each do |field| %>
<div class='col-xs-12'>
<%= f.label field.to_sym %><br>

<% autofocus = false unless count == 0 %>
<% if field == 'insulin' %>
<%= f.select field.to_sym,
options_for_select(@metric.class.send("#{field}_types".to_sym), insulin_for_time),
Expand All @@ -18,12 +22,13 @@
%>
<% else %>
<% if get_type(@metric, field) == :float %>
<%= f.number_field field.to_sym, class: 'form-control', step: 0.1, min: 0, autofocus: true %>
<%= f.number_field field.to_sym, class: 'form-control', step: 0.1, min: 0, autofocus: autofocus %>
<% else %>
<%= f.text_field field.to_sym, class: 'form-control' %>
<% end %>
<% end %>
</div>
<% count += 1 %>
<% end %>

<div class='col-xs-12 buttons'>
Expand Down

0 comments on commit f6f6782

Please sign in to comment.