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?

6
  • PLUNKER OT FIDDEL demo would be great :) Commented May 24, 2015 at 16:30
  • Text can't be selected when the input is disabled, it just doesn't work that way Commented May 24, 2015 at 16:33
  • So, I am going to have to make it a div then... Commented May 24, 2015 at 16:34
  • 1
    readonly attrib should give you a similar result Commented May 24, 2015 at 16:34
  • @OliverBarnwell that does exactly what I want! Commented May 24, 2015 at 16:36

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.