Readonly attribute in knockoutjs

HTML:

<input data-bind="value: text, readOnly: locked"  ></input> 

In knockout:

  ko.bindingHandlers.readOnly = {
    update: function(element, valueAccessor) {
        var value = ko.utils.unwrapObservable(valueAccessor());
        if (value) {
            element.setAttribute("readOnly", true); 
        }  else {
            element.removeAttribute("readOnly");
        }  
    }  
}
 
var viewModel = {
   
    locked = ko.observable(false)
};