尝试在模式对话框内创建表单。但我希望这个表单包含来自 jquery 的日期选择器和其他小部件。
目前我正在这样做:
在 View 中:
<p><%= link_to "New Event", new_event_path, :remote => true%></p>
在 application.js 中
jQuery(function($) {
$('a[data-remote]').live('ajax:beforeSend', function(e, xhr, settings){
xhr.setRequestHeader('accept', '*/*;q=0.5, text/html, ' + settings.accepts.html);
});
$('a[data-remote]').live('ajax:success', function(event, data, status, xhr){
$('#modal').html(data);
$('#modal').dialog({
show: "slide",
hide: "slide",
draggable: true,
modal: true });
});
});
如果在我放置的页面顶部的部分
<script>$(function (){
$('#event_date').datepicker();
});
</script>
然后,当模式对话框显示时,我的日期字段将与日期选择器一起出现,但理想情况下我希望将此代码放在 application.js 中,而不是放在 View 中。
我是 jquery 新手,这也许就是我发现这很难做到的原因。欢迎任何建议!
最佳答案
将日期选择器初始化放在对话框的open
回调中!
$('a[data-remote]').live('ajax:beforeSend', function(e, xhr, settings){
xhr.setRequestHeader('accept', '*/*;q=0.5, text/html, ' + settings.accepts.html);
});
$('a[data-remote]').live('ajax:success', function(event, data, status, xhr){
$('#modal').html(data);
$('#modal').dialog({
show: "slide",
hide: "slide",
draggable: true,
modal: true,
open: function(event, ui){
$('#event_date').datepicker();
}
});
});
关于jquery - 模式对话框 Jquery-UI 中的日期选择器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6043561/