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