1

I am trying to auto select text in an input field when it is clicked, but when the field is disabled the auto select doesn't work.

Here is my Html:

<input type="text" class="form-control" ng-model="gameId" select-on-click disabled="true">

And here is my JavaScript:

angular.module('Admin').directive('selectOnClick', function(){
    return {
        restrict: 'A',
        link: function(scope, element, attrs){
            element.on('click', function(){
                this.select();
            });
        }
    };
});

I would like the text to be selectable when the form is disabled, how can I do that?

Get Off My Lawn
  • 34,175
  • 38
  • 176
  • 338

1 Answers1

1

The disabled attribute doesn't allow text to be selected. A solution is to use the readonly attribute.

However it should be noted that they don't provide exactly the same behaviour, this is expanded upon in more detail in this post

Community
  • 1
  • 1
Oliver Barnwell
  • 491
  • 4
  • 18