繁体   English   中英

如何在搜索文本框中输入日期值时避免Ajax错误?

[英]How to avoid ajax error while typing a date value in search textbox?

我有一个日期搜索功能,可以立即输入完整的日期输入,例如:('10/30/2019'),但如果我输入它,例如:('10 /'),它会抛出一个ajax错误(截图)附)。

我的bal.js文件:

$(document).ready(function() {
  $("table[role='bal_datatable']").each(function() {
    var table = $(this).DataTable({
      "order": [
        [7, "desc"]
      ],
      columnDefs: [{
          "searchable": false,
          "targets": 9
        },
        {
          "searchable": false,
          "targets": 10
        },
        {
          "orderable": false,
          "targets": 9
        },
        {
          "orderable": false,
          "targets": 10
        },
        {
          "className": "abc",
          "targets": [5]
        }
      ],
      autoWidth: false,
      pageLength: 50,
      processing: true,
      serverSide: true,
      ajax: $(this).data('url')
    });

    // Setup - add a text input to each footer cell
    $('#balances tfoot th').each(function(i) {
      var title = $(this).text();
      $(this).html('<input type="text" placeholder="' + title + '" />');


      $('input', this).on('keyup change', function() {
        if (table.column(i).search() !== this.value) {
          table
            .column(i)
            .search(this.value)
            .draw();
        }
      });

    });

  });
})

我的bal_datatable.rb:

def bal_method1(balances)
  if(@tabular.search7 > '00/00/0000' )
    balances.where("balances.updated_at > (:search) and balances.updated_at < (date (:search) + interval '1 day')", {search: "#{@tabular.search7}"})
  else
    balances.where("1 = 1")
  end
end

该图显示了在搜索文本框中输入“ 03 /”后的错误

请帮忙。

if( this.value.match(/(\d{2}\/\d{2}\/\d{4})/))
            { table.column(i).search( this.value ).draw(); }
            else if( this.value == '')
            { table.column(i).search( this.value ).draw(); }

暂无
暂无

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

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