3

I'm using knockout.js for an editable table, and I'm trying to fire a validation function when an input field value within the table is changed.

I have tried using an editable computed observable: change event on select with knockout binding, how can i know if its a real change (mhu's answer)

I have tried using observable extenders: KO Extenders

I have also tried using the change event:

JSFiddle!

Each time I have tried, only the original value is returned.

What is the standard way to intercept the new value of an observableArray item in order to validate the new value? Is this not bread-and-butter stuff for KO?

Community
  • 1
  • 1
Oliver
  • 8,794
  • 2
  • 40
  • 60
  • Have you looked at https://github.com/Knockout-Contrib/Knockout-Validation? – Anders Sep 19 '13 at 09:23
  • I'd rather not use extra libraries if possible however I will as a last resort. I thought this would be simple with KO. – Oliver Sep 19 '13 at 09:38

1 Answers1

9

Change your databind statment from

data-bind="attr: { value: itemValue  }, event: { change: $parent.itemChanged }"

to

data-bind="value: itemValue, event: { change: $parent.itemChanged }"

working fiddle: http://jsfiddle.net/hztaS/

robasaurus
  • 1,022
  • 8
  • 15