Custom valueUpdate event

263 views
Skip to first unread message

Todd Sharp

unread,
Feb 23, 2012, 9:16:43 AM2/23/12
to KnockoutJS
I'm pretty new to Knockout - coming from the Flex world where binding
is pretty mature so I've got some questions as to how binding works in
the JS/Knockout world.

Is there a way to create a custom event for valueUpdate so that I can
defer updating my model until an object has been validated/saved?

Ultimately it'd be pretty cool to be able to do something like this:

<input type="text" data-bind="value: name, valueUpdate:
'onCustomEvent'" />

I thought I'd work around this limitation by specifying no (or a null)
valueUpdate and manually calling notifySubscribers() but it appears
that valueUpdate fires onBlur by default (even if I pass null).

Am I off in thinking that this would be a valid use case? I'm just
trying to consider a 'Cancel' or 'Reset' situation on an edit form
where I don't want to leave my model dirty when a user decides not to
save.

Thanks!

Michael Best

unread,
Feb 23, 2012, 10:09:19 AM2/23/12
to KnockoutJS
I think the way to do validation is to use a writable computed
observable to filter writes to the value. You could do this with an
extender that creates and returns the wrapping *computed*.

See http://knockoutjs.com/documentation/extenders.html
Reply all
Reply to author
Forward
0 new messages