我正在使用 jquery-timepicker 制作调度工具。我有一个@tour,它有一个 start_date 和一个 end_date,我已经通过控制器传递了它。
在时间选择器中,我想将 hourMin 和 hourMax 分别限制为 @tour 的当前 start_date 和 end_date。现在,我收到一个错误,即tour does not exist。
不太熟悉 ajax 代码如何从当前的 start_date 和 end_date 获取信息,以及如何访问这个 tour 变量。
真的很感谢提前的帮助!!
<div class="panel-body">
<%= form_for [@facility, @tour] do |f| %>
<div class="row">
<div class="col-md-6">
<label>Start Availability</label>
<%= f.text_field :start_date, readonly: true, placeholder: "Start Date", class: "form-control datepicker" %>
</div>
<div class="col-md-6">
<label>End Availability</label>
<%= f.text_field :end_date, readonly: true, placeholder: "End Date", class: "form-control datepicker"%>
</div>
</div>
<br/>
<%= f.submit "Save", id: "btn_book", class: "btn btn-normal btn-block", disabled: true %>
<% end %>
</div>
<script>
function checkDate(date) {
dmy = (date.getDate()-1) + "-" + (date.getMonth() + 1) + "-" + date.getFullYear();
return [$.inArray(dmy, unavailableDates) == -1];
}
$(function() {
unavailableDates = [];
$.ajax({
url: '<%= preload_facility_path(@facility) %>',
dataType: 'json',
success: function(data) {
$.each(data.unavailable_dates, function (arrID, arrValue) {
console.log(arrValue)
unavailableDates.push($.datepicker.formatDate('yy-mm-dd', new Date(arrValue)));
});
console.log(unavailableDates)
var startDateTextBox = $('#tour_start_date');
var endDateTextBox = $('#tour_end_date');
$.timepicker.datetimeRange(
startDateTextBox,
endDateTextBox,
{
dateFormat: "yy-mm-dd",
timeFormat: "H:mm:ss",
hourMin: tour.start_date,
hourMax: tour.end_date,
stepHour: 1,
stepMinute: 15,
range: true,
minDate: '2d',//how many days after current day
start: {}, // start picker options
end: {}, // end picker options
beforeShowDay: checkDate,
onSelect: function(selected) {
$('#btn_book').attr('disabled', false);
}
}
);
}
});
});
</script>