Sudarshan Sudarshan - 7 months ago 50
HTML Question

Convert value into lower case before knockout binding

Demo Here

I bound a label with knockoutjs. The value bound always should be in lower case. While it will remain in uppercase in js model. How to do this ?


Javascript


var model = {
name:ko.observable("Test")
}

ko.applyBindings(model);



HTML


<label data-bind="text:name">

Answer

you just need to use toLowerCase in the view

view :

<div class='liveExample'>   
     <p> name: <label data-bind='text: name().toLowerCase()'></label></p> 
</div>

<b>Original Value:
<pre data-bind="text:ko.toJSON($data,null,2)"></pre>

sample working fiddle here

Comments