3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Date Range Pickerでnull(空白)許容する

Posted at

DateRangePickerでnullを許容したくてなかなかできずハマった。

nullを許容する場合
autoUpdateInput: false
をオプション指定すればnullになるが、日付を指定した場合に反映されない。
コールバック関数で指定してあげれば反映される。


$(function () {
    $(function () {
        "use strict";

        moment.locale("ja");
        $('#selector').daterangepicker({
            singleDatePicker: true,
            calender_style: "picker_3",
            format: 'YYYY/MM/DD',
            //初期値NULLにする&NULL許容する
            autoUpdateInput: false,
            locale: {
                cancelLabel: 'Clear'
            },
        },
            //autoUpdateInputが入っていると日付指定できなくなるのでcallback関数で指定する
            function (date) {
                $('#selector').val(date.format('YYYY/MM/DD'));
            }
        );
    });
});

参考
http://www.daterangepicker.com/#ex5

3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?