Search code examples
jquerytwitter-bootstrapbootstrap-datepicker

DatePicker: combine quarterly picker with submit functionality


How to combine a quarter datePicker

(see: SO: how-to-change-bootstrap-datepicker-month-view-to-display-quarters

jsfiddle: http://jsfiddle.net/4mwk0d5L/1/ )

with a submit functionality?

(like: SO: bootstrap-datepicker-how-to-send-value-to-url?)

I tried:

$('#example1').datepicker({
    format: "MM yyyy",
    minViewMode: 1,
    autoclose: true,
    language: "qtrs",
    forceParse: false
}).on("show", function (event) {

    $(".month").each(function (index, element) {
        if (index > 3) $(element).hide();
    });
}).on('changeDate', function () {
    $(this).parent('form').submit();
});

but it does not seem to work.

Here is the jsFiddle I have used: http://jsfiddle.net/a1t465c7/


Solution

  • Yes, It should work. Content inside changeDate event is executed. Try this:

    $('#example1').datepicker({
        format: "MM yyyy",
        minViewMode: 1,
        autoclose: true,
        language: "qtrs",
        forceParse: false
    }).on("show", function (event) {
    
        $(".month").each(function (index, element) {
            if (index > 3) $(element).hide();
        });
    }).on('changeDate', function () {
        alert('test');
    });
    

    See here: http://jsfiddle.net/76Lhvfy0/

    May be a problem with the following instruction:

    $(this).parent('form').submit();