I have two problems with the same aspect of my application, abstract view:
The application allows users to view different video clips. In the back-end / admin area, the administrator can monitor the views of any group of clips. For example, an administrator can select Universal Studios, select, date range: Beginning Date: 2015-01-1, End Date: 2016-01-1and click filter, and see the number of total views received Universalin this range.
The problem is that the datepicker is no longer working, so when I click on the date fields the calendar does not appear, I need to manually enter the date. And for two, I get only the results: 2015-10-18and 2016-02-18. When I type 2015-09-18or something earlier, it does not generate results.
Below is the error when I click the check item in Chorme,
Error: Unprepared TypeError: Unable to read the "apply" property from undefined
*/
(function($) {
var _datepicker = jQuery.fn.datepicker;
$.fn.datepicker = function(options) {
var $date = _datepicker.apply(this, arguments); <--- this line
application.js requires
Update according to Robs point:
custom.js
(function($) {
var _datepicker = jQuery.fn.datepicker;
$.fn.datepicker = function(options) {
var $date = _datepicker.apply(this, arguments);
if (options.altFormat && options.altField) {
var altValue = $(options.altField).val();
var value = $.datepicker.parseDate(options.altFormat, altValue);
var dateFormat = _datepicker.call(this, 'option', 'dateFormat');
$(this).val($.datepicker.formatDate(dateFormat, value));
}
};
})(jQuery);
var $date = $("#search_start_date");
$date.datepicker({
dateFormat: "yy-mm-dd",
altFormat: "yymmdd"
});
var $end_date = $('#search_end_date');
$end_date.datepicker({
dateFormat: "yy-mm-dd",
altFormat: "yymmdd"
});
});
index.html.erb
<%= form_for Search.new, url: statistics_search_saas_admin_statistics_path, html: {method: :get, remote: true} do |f| %>
<table id="table_1" class="table" style="margin-bottom: 5px;">
<tr>
<th style="color: black; background: white; border-color: white;">Studio</th>
<th style="color: black; background: white; border-color: white;">Film</th>
<th style="color: black; background: white; border-color: white;">Clip</th>
<th style="color: black; background: white; border-color: white;"></th>
<th style="color: black; background: white; border-color: white;"></th>
</tr>
<tr>
<td>
<select multiple id="studio_select" style="height: 150px;">
<% Studio.all.each do |studio| -%>
<option value="<%=studio.id %>"><%= studio.name %></option>
<% end -%>
</select>
<%= hidden_field_tag :studio_ids %>
</td>
<td>
<select multiple id="film_select" style="height: 150px;"></select>
<%= hidden_field_tag :film_ids %>
</td>
<td>
<select multiple id="clip_select" name="search[clip]" style="height: 150px;"></select>
<%= hidden_field_tag :clip_ids %>
</td>
</table>
<div class="span10">
<table class="table">
<tr>
<th>Beginning Date</th>
<th>End Date</th>
<th></th>
</tr>
<tr>
<td><%= f.text_field :start_date, value: 1.month.ago.strftime('%Y-%m-%d') %></td>
<td><%= f.text_field :end_date, value: Time.now.strftime('%Y-%m-%d') %></td>
<td>
<%= f.submit "Filter", class: "btn btn-danger", data: {disable_with: 'Searching...'} %>
<%= link_to 'Clear Form', '#', id: "clear", class: 'btn btn-default' %>
</td>
</tr>
</table>
</div>
<% end -%>