我有一个在开发环境中运行良好的嵌套字段页面。我使用插入后回调对字段标签进行编号。所以这会创建“pericoop 1,pericoop 2”标签。但是,当我从 rspec 测试页面时,标签没有编号。当我保存_and_open_page 时,我只看到文本“pericoop”。因此,无论出于何种原因,似乎都没有触发回调。
这是我的 rspec:
scenario 'to multiple pericopes with valid attributes', js: true do
fill_in 'pericoop 1', with: 'Jona 1:1 - 1:10'
click_on 'Voeg nog een pericoop toe'
should_see 'pericoop 2'
fill_in 'pericoop 2', with: 'Jona 2:20 - 3:3'
submit_form
should_see 'Jona 1:1 - 10 | Jona 2:20 - 3:3'
end
还有咖啡脚本
$ ->
$("#pericopes").on "cocoon:after-insert", (event, added_item) ->
num = $("#pericopes div.nested-fields").length
added_item.find('.control-label').html('pericoop '+num)
console.log('pericope numbered')
从测试运行时控制台日志不显示任何内容(我已将 Firefox 配置为保留日志)。
表格:
= simple_form_for studynote, validate: true do |f|
#pericopes
= f.simple_fields_for :pericopes do |ff|
.nested-fields
= ff.input :name,
label: "#{t('simple_form.labels.pericopes.name')} 1",
placeholder: 'Genesis 1:1-3:21',
autofocus: true
= link_to_remove_association 'remove pericope', ff
.links
= link_to_add_association t('add_pericope'), f, :pericopes
= f.input :title
= f.input :note, :input_html => { :rows => 20 }
= f.button :submit, class: "btn-primary"
和部分:
.nested-fields
= f.input :name,
label: "#{ t('simple_form.labels.pericopes.name') }",
placeholder: 'Genesis 1:1-3:21',
autofocus: true
= link_to_remove_association 'remove pericope', f
编辑,我已经重构了表单和部分代码以干掉一些代码,希望这可以解决问题,但还没有运气。部分 _pericope_fields.html.haml
.nested-fields
- index = index
= f.input :name,
label: "#{ t('simple_form.labels.pericopes.name') } #{index}",
placeholder: 'Genesis 1:1-3:21',
autofocus: true
= link_to_remove_association 'remove pericope', f
表格,_form.html.haml
= simple_form_for studynote, validate: true do |f|
#pericopes
= f.simple_fields_for :pericopes do |pericope|
= render 'pericope_fields', f: pericope, index: 1
.links
= link_to_add_association t('add_pericope'), f, :pericopes, class: 'new btn-xs'
= f.input :title
= f.input :note, :input_html => { :rows => 20 }
= f.button :submit, class: "btn-primary"
我看过这篇文章,300 ,但那里的回调根本不起作用。还有另一篇文章(我现在找不到),其中规范不包含 js:true。但这不是这里的问题。
任何想法这里可能有什么问题?