Selecting the entire contents of text input in focus at the edge of microsoft

It seems that I ran into a problem related to the edge when selecting all the text in the input field. I use angular ng-focus to call a function in the controller to select all the text in the field.

function selectAllTextOnFocus($event) {
    $event.target.select();
}

This works fine in all browsers except the microsoft edge, which will not select text in the input field.

I also tried another jquery solution that works, except for the first selection of the input field. After that, he works as intended and selects all the text.

$('input').on('focus', function (e) {
    $(this).one('mouseup', function () {
        $(this).select();
        return false;
    }).select();
});

Is this just a known edge issue or am I missing something?

+4
source share
1 answer

Microsoft Edge , . select :

function selectAllTextOnFocus($event) {
    // See https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/8229660/
    if ( navigator.userAgent.match(/Edge\/(13|14)/) ) {
        return setTimeout( $event.target.select.bind( $event.target ), 10)
    }
    $event.target.select();
}

: https://jsfiddle.net/jonathansampson/xe9x9s7b/

http://bugs.microsoftedge.com .

+4

Source: https://habr.com/ru/post/1648548/


All Articles