Last active
December 11, 2017 21:15
-
-
Save janosorcsik/b7ec1b0dc031456996a70984f0ad62b9 to your computer and use it in GitHub Desktop.
Knockout readonly handler
This file contains 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
ko.bindingHandlers['readonly'] = { | |
'update': function (element, valueAccessor) { | |
var value = ko.utils.unwrapObservable(valueAccessor()); | |
if (!value && element.readOnly) | |
element.readOnly = false; | |
else if (value && !element.readOnly) | |
element.readOnly = true; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment