1
I have a problem that seems to be simple, but it has taken me a long time looking for possible solutions and so far I have not been able to solve.
I need to select the content of an Input in an HTML form with Bootstrap when receiving Focus.
By default HTML5 already selects the field content when receiving Focus, but I am using an Angularjs( ng-currency ) directive to format decimals, and after adding the directive no longer selects.
In short...
What I want ?
Well an image is worth more than a thousand words, when receiving Focus(tab for example) I want the content of the input to be all selected on the screen:
What I’ve tried to do?
I was able to do it in the click event inside the field, like this:
<input type="text"
class="col-sm-12 form-control"
ng-model="campo"
ng-currency currency-symbol=""
ng-click="selectAllClick($event)">
$scope.selectAllClick = function ($event) {
$event.target.select();
}
But accurate in the event of Focus, I have tried to use ng-Focus to call this function, but it does not work.
The directive I’m using is this: https://github.com/aguirrel/ng-currency
The problem is this:
Does anyone have any idea?
Have you tried
onclick="this.select()"
?– João Victor Gomes Moreira
I’ve tried yes, onclick works, but onfocus doesn’t.
– Geferson
I tried to use so, I saw here in the forum: onfocus="this.select();" onmouseup="Return false;", but also did not solve
– Geferson
in the test I did here using that same code worked normal, even using the tab, weird, I’ll try something else here
– João Victor Gomes Moreira
So, for me it only works if I click inside the field, or if I take ng-currency out of the input, then it works right.
– Geferson
Well, the only thing that changes is that I have this input inside a table, but even if I test outside of it, it doesn’t work either.
– Geferson
You want to select while hovering over?
– João Victor Gomes Moreira
No, entering the field, via tab is what I need.
– Geferson
I updated the image of how it currently happens, when entering the field it plays the | to the last element, and I want it to come selected.
– Geferson
Let’s go continue this discussion in chat.
– João Victor Gomes Moreira