我在 ActiveScaffold 的表单上有一个 Select 下拉菜单。如果选择了特定值,我试图隐藏表单上的某些字段。
[类似问题][1] 已发布到 ActiveScaffold Google Group,提供的原型代码看起来可以满足我的需要,但是我不知道我需要在哪里添加它。
--
我尝试从 Vendor/plugins/active_scaffold/frontends/default/views 获取 -horizontal-subform-header.html.erb 的副本,将其放在控制器的 views 文件夹中,然后将我的脚本添加到其中:
<script type="text/javascript">
document.observe('dom:loaded', function() { //do it once everything's loaded
//grab all the product-input classes and call 'observe' on them :
$$('.product-input').invoke('observe', 'change', function(e) {
this.up('td').next('td').down('input').hide();
});
});
</script>
...但这似乎无法正常工作。如果我使用 URL 直接进入表单(即http://localhost:3000/sales/20/edit?_method=get),它会起作用。但是当我用主列表视图(即http://localhost:3000/sales/)测试它并通过 Ajax 打开表单时,它就不起作用了。查看 HTML 源代码,只是没有出现。