Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

KnockoutJS how to bind textarea value property to function

I have simple textarea that i want to customize it's text(like add break-lines), that's what I have tried so far:

<textarea rows="5" data-bind="value: function(data) { SetDefaultValue(data); }" />

but I get nothing.

When checking the resulting HTML it doesn't find the value property and has no JavaScript errors. How can I bind value property of a textarea to function.

Jsfiddle Demo

like image 240
ebram khalil Avatar asked Jul 09 '13 10:07

ebram khalil


1 Answers

You can do it like this:

<textarea rows="5" type="text" data-bind="value: SetValue(firstName)" />

and than in javascript:

function AppModel() {
this.firstName = "ebram";
this.lastName = "Tharwat";
this.SetValue = function (data) {
    //Do the processing over here
    return data.toUpperCase();
   }
}
ko.applyBindings(new AppModel());
like image 83
Imran Balouch Avatar answered Oct 03 '22 11:10

Imran Balouch