This is a migrated thread and some comments may be shown as answers.

Localization in MVVM

2 Answers 144 Views
Upload
This is a migrated thread and some comments may be shown as answers.
Dorian
Top achievements
Rank 2
Dorian asked on 04 Jun 2014, 06:42 AM
I'm trying to do localization for the upload widget using the bindings of the mvvm approach.

<input type="text" id="upload_field" data-role='upload' data-localization='{"select": local_select}' />

with local_select being a parameter from my observable object.

var uploadModel =  new kendo.data.ObservableObject({
local_select:"Izberi..."
});

which is turn bound - var kendoView = kendo.bind($("#portal_content"), uploadModel);

The expected result is to the input itself showing the content from the object model but it throws an error (undefined) and crashes everything after it.
If I try using the #= # approach it crashes yet again with saying it's an illegal token. Finally I wrote a string  data-localization='{"select": "Izberi..."}' and it works. It also works if I use any directly accessible js variable. Since I haven't had any significant problems binding any other values to other widgets so far (ok, there have been problems but mostly typos on my side :) ).

Is there something I'm doing wrong or does kendo have problems binding these values? I did at first thought that you don't have mvvm bindings so I created an extended widget out of upload.

kendo.data.binders.widget.localization.select = kendo.data.Binder.extend({
                    init: function (widget, bindings, options) {
                        //call the base constructor
                        kendo.data.Binder.fn.init.call(this, widget.element[0], bindings, options);
                    },
                    refresh: function () {
                        var that = this,
                        value = that.bindings["localization-select"].get(); //get the value from the View-Model
                        $(that.element).data("kendoRcgUpload").localization.select(value); //update the widget
                    }
});

But that hasn't worked out either. So I'm currently at a loss what else I could do - And I need to bind the value from the model since I need my code clean as a whistle :)




2 Answers, 1 is accepted

Sort by
0
Dorian
Top achievements
Rank 2
answered on 04 Jun 2014, 09:37 AM
Since I can't edit - I accidentally pasted an older code sample:

This is the correct code used in my application:

kendo.data.binders.widget.localization = kendo.data.Binder.extend({
        init: function (widget, bindings, options) {
            //call the base constructor
            kendo.data.Binder.fn.init.call(this, widget.element[0], bindings, options);
        },
        refresh: function () {
            var that = this,
            value = that.bindings["localization"].get(); //get the value from the View-Model
            console.log(value)
            $(that.element).data("kendoRcgUpload").localization(value); //update the widget
        }
    });
0
Accepted
T. Tsonev
Telerik team
answered on 06 Jun 2014, 06:38 AM
Hello,

The data-localization option is not actually a binding, but a declarative initialization. It has access only to the global scope, but not to the model variables.
Creating a custom binding is definitely the way to go, but the problem is that the Upload can't update its localization strings once rendered.

Apologies for the caused inconvenience.

Regards,
T. Tsonev
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
Tags
Upload
Asked by
Dorian
Top achievements
Rank 2
Answers by
Dorian
Top achievements
Rank 2
T. Tsonev
Telerik team
Share this question
or