Lara
Lara

Reputation: 301

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?

Upvotes: 5

Views: 12964

Answers (4)

Amritpal Singh
Amritpal Singh

Reputation: 11

Use minMode:'month' in the datepicker-options and it will work.

Upvotes: 1

ubirajara
ubirajara

Reputation: 21

There is an angular version of the eternicode's bootstrap-datepicker here: angular-bootstrap-datepicker

Upvotes: 0

Lara
Lara

Reputation: 301

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");
};

Upvotes: 1

ThomasC
ThomasC

Reputation: 8165

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.

Upvotes: 2

Related Questions