Skip to content

Instantly share code, notes, and snippets.

@keepitsimple
Last active August 29, 2015 14:15
Show Gist options
  • Save keepitsimple/38870eba596608c75437 to your computer and use it in GitHub Desktop.
Save keepitsimple/38870eba596608c75437 to your computer and use it in GitHub Desktop.
Knockout.js 'valueInit' binding (initialize value from html markup)
ko.bindingHandlers.valueInit =
init: (element, valueAccessor) ->
property = valueAccessor()
if !ko.isWriteableObservable(property)
throw new Error 'Knockout "valueInit" binding expects an observable.'
property element.value
#html example
#<input data-bind="value: message, valueInit: 'Hello world'" />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment