twitter-bootstrap 在引导模式窗口中提交表单时创建 fullCalendar 日历事件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14207318/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Create fullCalendar calendar event on submitting the form in bootstrap modal window
提问by Destiny In Ur Hands
I've a fullCalendar implementation and am trying to create a bootstrap modal window on clicking anywhere on the calendar and then saving the calendar entry on "submitting" the form in the modal window.
我有一个 fullCalendar 实现,并试图通过单击日历上的任意位置创建一个引导模式窗口,然后在模式窗口中“提交”表单时保存日历条目。
$(document).ready(function() {
var calendar = $('#calendar').fullCalendar({
//header and other values
select: function(start, end, allDay) {
var endtime = $.fullCalendar.formatDate(end,'h:mm tt');
var starttime = $.fullCalendar.formatDate(start,'ddd, MMM d, h:mm tt');
var mywhen = starttime + ' - ' + endtime;
$('#createEventModal #when').text(mywhen);
$('#createEventModal').modal('show');
},
//other functions
});
Here's the HTML for modal screen:
这是模态屏幕的 HTML:
<div id="createEventModal" class="modal hide" tabindex="-1" role="dialog" aria-labelledby="myModalLabel1" aria-hidden="true">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">x</button>
<h3 id="myModalLabel1">Create Appointment</h3>
</div>
<div class="modal-body">
<form id="createAppointmentForm" class="form-horizontal">
<div class="control-group">
<label class="control-label" for="inputPatient">Patient:</label>
<div class="controls">
<input type="text" name="patientName" id="patientName" tyle="margin: 0 auto;" data-provide="typeahead" data-items="4" data-source="["Value 1","Value 2","Value 3"]">
</div>
</div>
<div class="control-group">
<label class="control-label" for="when">When:</label>
<div class="controls controls-row" id="when" style="margin-top:5px;">
</div>
</div>
</form>
</div>
<div class="modal-footer">
<button class="btn" data-dismiss="modal" aria-hidden="true">Cancel</button>
<button type="submit" class="btn btn-primary" id="submitButton">Save</button>
</div>
</div>
In another javascript file that's called within the main HTML, I've the following:
在主 HTML 中调用的另一个 javascript 文件中,我有以下内容:
$('#submitButton').on('click', function(e){
// We don't want this to act as a link so cancel the link action
e.preventDefault();
// Find form and submit it
$('#createAppointmentForm').submit();
});
$('#createAppointmentForm').on('submit', function(){
alert("form submitted");
$("#createEventModal").modal('hide');
$calendar.fullCalendar('renderEvent',
{
title: $('#patientName').val();,
start: start,
end: end,
allDay: allDay
},
true
);
This is not working. What am I doing wrong?
这是行不通的。我究竟做错了什么?
回答by mccannf
You need to preserve the start, endand allDayparameters from the selectfunction.
您需要保留函数中的start,end和allDay参数select。
For example, store them in hidden inputs in the dialog form:
例如,将它们存储在对话框表单中的隐藏输入中:
<div class="controls">
<input type="text" name="patientName" id="patientName" tyle="margin: 0 auto;" data-provide="typeahead" data-items="4" data-source="["Value 1","Value 2","Value 3"]">
<input type="hidden" id="apptStartTime"/>
<input type="hidden" id="apptEndTime"/>
<input type="hidden" id="apptAllDay" />
</div>
And in the selectfunction of fullcalendar set the values of the hidden fields:
在selectfullcalendar 函数中设置隐藏字段的值:
select: function(start, end, allDay) {
endtime = $.fullCalendar.formatDate(end,'h:mm tt');
starttime = $.fullCalendar.formatDate(start,'ddd, MMM d, h:mm tt');
var mywhen = starttime + ' - ' + endtime;
$('#createEventModal #apptStartTime').val(start);
$('#createEventModal #apptEndTime').val(end);
$('#createEventModal #apptAllDay').val(allDay);
$('#createEventModal #when').text(mywhen);
$('#createEventModal').modal('show');
}
And then you can use the values from these fields in the submit:
然后您可以在以下字段中使用这些字段中的值submit:
function doSubmit(){
alert("form submitted");
$("#createEventModal").modal('hide');
$("#calendar").fullCalendar('renderEvent',
{
title: $('#patientName').val(),
start: new Date($('#apptStartTime').val()),
end: new Date($('#apptEndTime').val()),
allDay: ($('#apptAllDay').val() == "true"),
},
true);
}

