Based on Nitin's work above, I created this Angular directive which should do the trick
Jsfiddle
http://jsfiddle.net/codemonkeytony/3ew5h6bf/7/
Angular
var partialApp = angular.module("partialApp", []); partialApp.directive('partialReadonly', function () { return { restrict: 'A', link: function (scope, elem, attrs) { elem.on('keypress, keydown', function (event) { var readOnlyLength = attrs["partialReadonly"].length; if ((event.which != 37 && (event.which != 39)) && ((elem[0].selectionStart < readOnlyLength) || ((elem[0].selectionStart == readOnlyLength) && (event.which == 8)))) { event.preventDefault(); } }); $(window).load(function () { elem[0].value = attrs["partialReadonly"]; }); } }; });
HTML
<input type="text" partial-readonly="Readonly text goes here" />
Hope this helps
source share