3

我正在使用 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 %>

我发现了这个: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>

用户.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'))
4

2 回答 2

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>

而这个 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();
  });
});

JS 代码的最后一行是搜索 BIP 表单的元素类型并分配,tabindex因此保持制表符的顺序。

更新:上述 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()
于 2012-12-12T23:27:34.417 回答
1

BIP 改变了它们的命名结构。它们还包括一些 tabindex 支持。

通过宝石 github:

HTML 选项:

如果您提供的选项不是明确的 best_in_place 选项,则在创建 best_in_place 跨度时将通过该选项。

因此,例如,如果您想将 HTML 选项卡索引添加到 best_in_place 跨度,只需将其添加到您的方法调用中:

<%= best_in_place @user, :name, tabindex: "1" %>

但是,我没有让这个开箱即用(或根本没有)。我最终改变了上面的 Ahmad 的 JS 解决方案以符合新的命名结构。尽管通过:select字段切换仍然是一个问题,但它工作得很好。

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

JS 不是我的强项。如果有人对通过:select下拉列表进行选项卡有任何建议,请回复!谢谢

于 2015-02-09T20:50:35.960 回答