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

dataValue overwriting observables and changing to simple objects #6

Open
skmasq opened this issue May 28, 2014 · 0 comments
Open

dataValue overwriting observables and changing to simple objects #6

skmasq opened this issue May 28, 2014 · 0 comments

Comments

@skmasq
Copy link

skmasq commented May 28, 2014

Problem I was having was adjusting correct observables and object structure to get back object but show in input box only one value of object.

Declaration:

<input data-bind="jqAuto: { value: $row()[$col().DBKey]().GLCode, dataValue: $row()[$col().DBKey], source: myOptions, inputProp: 'GLCode', labelProp: 'Description',valueProp: 'GLCode' }" />

Where $row()[$col().DBKey] = Object().GLCode in this:

Object = ko.observable({
    ID: 1,
    ItemCode: "Net Amount",
    // This needs to be observable for dataValue prop
    GLCode: ko.observable({
        ID: 1,
        // This needs to be observable otherwise it will throw string is not a function
        GLCode: ko.observable("sometext")
    })
});

and myOptions is:

myOptions = function(s,callback){
    callback([{
        ID: 2,
        // Notice this is not observable, because if it was
        // then input value would be [input HTMLInputElement] or something like that
        GLCode: "someothertext"
    }]);
}

So the problem was that these lines:

48: if (ko.isWriteableObservable(options.dataValue)) {
49:                     options.dataValue(ui.item.data);

were overwriting this:

GLCode: ko.observable({
        ID: 1,
        GLCode: ko.observable("sometext")
    })

to

GLCode: ko.observable({
        ID: 1,
        GLCode: "sometext"
    })

So I changed those line to this to preserve observables:

48: if (ko.isWriteableObservable(options.dataValue)) {
49:                     ko.mapping.fromJS(ui.item.data, {}, options.dataValue);

I hope this will help anyone struggling with the same issue.

@skmasq skmasq changed the title value and dataValue commnication issue dataValue overwriting observables and changing to simple objects May 28, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant