Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

validatedObservable bug when the initial value is undefined #442

Closed
thj-dk opened this issue Aug 12, 2014 · 2 comments · Fixed by #495
Closed

validatedObservable bug when the initial value is undefined #442

thj-dk opened this issue Aug 12, 2014 · 2 comments · Fixed by #495

Comments

@thj-dk
Copy link

thj-dk commented Aug 12, 2014

When the initial value of the validatedObservable is undefined, an observable is created with the validated property set to true. This is a problem, because one would expect the validatedObservable to be enabled when setting a future object.

crissdev added a commit that referenced this issue Jan 7, 2015
This commit also adds an internal method to update the state for the validation group.
This method is not intended to be used directly but to provide a way to update the
group until a better API will be implemented.

Closes #442
Closes #269
Closes #209
@mikocot
Copy link

mikocot commented Oct 16, 2015

I think the problem still persists if undefined (or null) is passed as the intial value (common case if you initialize your viewmodel, but fill it with date asynchronously). The code:

ko.validatedObservable = function (initialValue, options) {
       if (!options && !kv.utils.isObject(initialValue)) {
        return ko.observable(initialValue).extend({ validatable: true });
    }
       [...]

returns before it subscribes to the observable and therefore ko.validation.group is never called on the object after it is updated. Which means the content of the validatedObservable is never validated if only it was initialized with undefined once. On the other side... just pass anything (ex. true) in options and the issue is gone..

@crissdev
Copy link
Member

@mikocot See the following tests for more clarification https://github.com/Knockout-Contrib/Knockout-Validation/blob/2.0.3/test/api-tests.js#L714-L744
There's no way to tell, if the method is called with undefined, if you want groupping or not. So the default behaviour is correct but a hint from the consumer of the API is required (eg. options = {}) in order to achieve the desired functionality.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants