From f6f6782b6064d46e1dcd3cd695b6fe9df1299f79 Mon Sep 17 00:00:00 2001 From: pikesley Date: Sat, 20 Feb 2016 15:39:57 +0000 Subject: [PATCH] Always autofocus the _first_ field --- app/views/shared/_form.html.erb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/views/shared/_form.html.erb b/app/views/shared/_form.html.erb index 1421b27..5f4c13d 100644 --- a/app/views/shared/_form.html.erb +++ b/app/views/shared/_form.html.erb @@ -6,10 +6,14 @@ <%= f.label :datetime, 'Date and time' %>
<%= f.text_field :datetime, class: 'form-control datetime' %> + <% count = 0 %> + <% autofocus = true %> <% @metric.class.fields.each do |field| %>
<%= f.label field.to_sym %>
+ <% 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), @@ -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 %>
+ <% count += 1 %> <% end %>