简体   繁体   English

Bootstrap-datepicker onClose 事件问题

[英]Bootstrap-datepicker onClose event issue

I have two text inputs and I have bind a bootstrap date-picker to both of them.我有两个文本输入,并且我已经将引导日期选择器绑定到它们两个。 I want to fire an event when a date is selected.我想在选择日期时触发一个事件。 I can't use the dateChange because it is firing unnecessary events while doing so.我不能使用 dateChange 因为它在这样做时会触发不必要的事件。 So I want to set an event like onClose to fire an ajax call.所以我想设置一个像 onClose 这样的事件来触发 ajax 调用。 But the issue is that when I select the date and closes the datepicker it doesn't call the ajax but when I reopen it and then change the month by clicking the arrow the ajax is being called.但问题是,当我 select 日期并关闭日期选择器时,它不会调用 ajax 但是当我重新打开它然后通过单击箭头更改月份时,调用 Z2705A83A5A06537CCE345839726

   $('.filter_date').datepicker({
        onClose: function () {
              var form_data = [];
              form_data = originacion_ranking_data()
              if (form_data.length != 0){
                $.ajax({
                  type: 'POST',
                  url: '/visual_component/plot',
                  dataType: 'json',
                  data: {'form_data': JSON.stringify(form_data)},
                  success: function(data){
                    if (data != false){
                      $('#tableContents').val(encodeURIComponent(JSON.stringify(data)));
                    }
                  }
                });
              }
          }
  });  
<%= text_field_tag :start_date, params[:start_date], name: 'daterange', class: "form-control form-control-inline input-small date-picker date_range filter_date",size: "16" %>

<%= text_field_tag :end_date, params[:end_date], name: 'daterange', class: "form-control form-control-inline input-small date-picker date_range filter_date",size: "16" %>

Please help.请帮忙。

Instead of "onClose" event use "hide" event as documented in Bootstrap Evnets而不是“onClose”事件,而是使用Bootstrap Evnets中记录的“隐藏”事件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM