Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

angularjs ui-date to show month year only

I am using ui-date directive (https://github.com/angular-ui/ui-date).

This UI Calendar component is getting Date by default. Can I get only month and year without dates.

How to get only month and year?

like image 617
Lara Avatar asked Oct 01 '22 21:10

Lara


2 Answers

I don't know ui-date directive, but I had exactly the same need than you.

You can use eternicode's fork of bootstrap-datepicker and look for the min view mode parameter which will fit your need.

like image 173
ThomasC Avatar answered Oct 05 '22 05:10

ThomasC


Following Code work for me. Thanks

$scope.expireDate = {
    dateFormat: 'mm-yy',
    changeMonth: true,
    changeYear: true,
    showButtonPanel: true,
    onClose: function() {
        function isDonePressed() {
            return ($('#ui-datepicker-div').html().indexOf('ui-datepicker-close ui-state-default ui-priority-primary ui-corner-all ui-state-hover') > -1);
        }
        if (isDonePressed()) {
            var month = $("#ui-datepicker-div .ui-datepicker-month :selected").val();
            var year = $("#ui-datepicker-div .ui-datepicker-year :selected").val();
            $(this).datepicker('setDate', new Date(year, month, 1));
        }
    }
};

$scope.setExpireDate = function() {
    $(".ui-datepicker-calendar").hide();
    $("button.ui-datepicker-current").css("display", "none");
};
like image 43
Lara Avatar answered Oct 05 '22 05:10

Lara