Manually get knockout to re-evaluate a dependantObservable

后端 未结 2 983
野趣味
野趣味 2020-12-15 04:43

I am not sure if this is possible, but I have a scenario where I have a validation system which notifies my validation system when something has become valid/invalid via a d

相关标签:
2条回答
  • 2020-12-15 04:49

    On your computed observable (isValid) you can call notifySubscribers(currentValue), which will notify any subscribers with the current value. It will not re-evaluate the computed and will simply notify subscribers with the current value.

    0 讨论(0)
  • 2020-12-15 05:11

    Add binding enable: formValid where formValid = ko.computed(return true if all values are valid) to submit button. This way user can not submit until form is filled properly.

    Use ko.validation.validateObservable(yourDependentObservable) to revalidate field manually

    or use yourObsevable.notifySubscribers() if yourDependentObservable depends on yourObservable.

    0 讨论(0)
提交回复
热议问题