Position caret in Phone Field [RESOLVED]

I have encountered this with input masks before. The following script can be used to force cursor placement to the start of the input when focused:

// force cursor placement on input mask
var maskedPhones = document.querySelectorAll('.gfield .ginput_container_phone input');

for (i = 0; i < maskedPhones.length; ++i) {
  maskedPhones[i].addEventListener('mouseup', function(e) {
    if ( e.currentTarget.value.replace(/\(|\)|_|-|\./g,'').trim() == '' ) { e.currentTarget.setSelectionRange(0,0); }
  });
}

This code is specific to masked phone inputs. It could be modified to target other input masks, as needed.

1 Like