ruby-on-rails - Best_in_place 标签槽

标签 ruby-on-rails best-in-place

我正在使用 best_in_place gem,因此我可以在我的索引 View 中编辑多个学生。

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

这是我可以按 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.咖啡

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'))

最佳答案

我认为您可以像这样使用 tabindex HTML 属性和 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 以保持 Tab 键的顺序。

更新:上述 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()

关于ruby-on-rails - Best_in_place 标签槽,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13849166/

相关文章:

ruby-on-rails - 通过 rake 测试重置测试数据库提示 : "database configuration does not specify adapter"

ruby-on-rails-3 - 如何将 Best In Place 与 twitter bootstrap 结合使用

ruby-on-rails-3 - best_in_place 日期选择器格式

ruby-on-rails-3 - Rails best_in_place jQuery 就地编辑 :activator button not working

ruby-on-rails-3 - 我如何将 country_select gem 与 best_in_place 编辑集成

ruby-on-rails - ActiveModel 动态属性类型

ruby-on-rails - rails : How do I write tests for a ruby module?

ruby-on-rails - 在 Ruby 中解析(在 Rails 上)

ruby-on-rails - Rails 将对象保存到 cookie

jquery - Rails - 带有日期的 best_In_place gem