-
-
Save jpolvora/c2204c549d51dd8bb0469d9ef5782688 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* read-only date display with momentjs | |
* use like this: data-bind="moment: dateVar, format: 'YYYY-MM-DD'" | |
* The "format" is optional and will default to "MM/DD/YYYY" | |
*/ | |
ko.bindingHandlers.moment = { | |
update: function (element, valueAccessor, allBindingsAccessor, viewModel) { | |
var val = valueAccessor(); | |
var date = moment(ko.utils.unwrapObservable(val)); | |
var format = allBindingsAccessor().format || 'MM/DD/YYYY'; | |
element.innerText = date.format(format); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment