Best_in_place标签槽

All*_*lan 3 ruby-on-rails best-in-place

我正在使用best_in_place gem,因此我可以在索引视图中编辑多个学生.

但问题是,可用性很差.我必须单击,键入信息,输入/单击并再次单击以编辑其他信息.

这是一种我可以按Tab键去田野的方式吗?

这是索引的代码:

<% @students.each do |student| %>
   <tr>
   <td><%= link_to .name, edit_student_path(student) %></td>
   <td><%= best_in_place student, :oral %></td>
   <td><%= best_in_place student, :writing %></td>
   <td><%= best_in_place student, :participation %></td>
   <td><%= best_in_place student, :grammar %></td>
   <td><%= best_in_place student, :presence, type: :select, collection: [["Present", "Present"], ["Absent", "Absent"], ["", "-"]] %></td>
   </tr>
<% end %>
Run Code Online (Sandbox Code Playgroud)

我发现了这个:https://github.com/bernat/best_in_place/tree/master/lib/best_in_place

好.这就是我现在得到的,但仍然没有工作:/任何想法?

指数:

 <td><%= best_in_place allan, :oral, :html_attrs => {:tabindex => 10} %></td>
 <td><%= best_in_place allan, :writing, :html_attrs => {:tabindex => 11} %></td>
Run Code Online (Sandbox Code Playgroud)

Users.js.coffee

jQuery ->
$('.best_in_place').best_in_place()

$ ->
  $('span.best_in_place').focus ->
   el = $(this)
   el.click()
   el.find(el.data('type')).attr('tabindex', el.attr('tabindex'))
Run Code Online (Sandbox Code Playgroud)

Ahm*_*rif 5

我认为你可以使用像这样的tabindexHTML属性和focus事件来破解一下:

   <td><%= best_in_place student, :oral, :html_attrs => {:tabindex => 10} %></td>
   <td><%= best_in_place student, :writing, :html_attrs => {:tabindex => 11} %></td>
   <td><%= best_in_place student, :participation, :html_attrs => {:tabindex => 12} %></td>
   <td><%= best_in_place student, :grammar, :html_attrs => {:tabindex => 13} %></td>
   <td><%= best_in_place student, :presence, type: :select, collection: [["Present", "Present"], ["Absent", "Absent"], ["", "-"]], :html_attrs => {:tabindex => 14} %></td>
Run Code Online (Sandbox Code Playgroud)

而这个JS

$(function() {
  $('span.best_in_place[data-html-attrs]').each(function() {
    var attrs, el;
    el = $(this);
    attrs = el.data('html-attrs');
    if (attrs && attrs['tabindex']) {
      el.attr('tabindex', attrs['tabindex']);
    }
  }).focus(function() {
    var el;
    el = $(this);
    el.click();
  });
});
Run Code Online (Sandbox Code Playgroud)

JS代码的最后一行是搜索BIP表单的元素类型并分配,tabindex以便保持tabbing的顺序.

更新:以上JS的CoffeeScript版本

$ ->
  $('span.best_in_place[data-html-attrs]').each ->
    el = $(this)
    attrs = el.data('html-attrs')
    el.attr('tabindex', attrs['tabindex']) if attrs and attrs['tabindex']
  .focus ->
    el = $(this)
    el.click()
Run Code Online (Sandbox Code Playgroud)