ui-utils icon indicating copy to clipboard operation
ui-utils copied to clipboard

Applying ui-mask on multiple fields on a form sets focus on the last masked input box automatically

Open uttarap opened this issue 12 years ago • 12 comments

This is a weird issue I came across and I wanted to see if I can do something so it does not set the focus on any particular input box. I have multiple date inputs on a form and I am using ui-mask to set a date mask. Let's say I have 4 input boxes with the mask on them. Once the form renders the focus is set on the 4th (last) input box which has the date mask on it. Is there any place I can disable that?

uttarap avatar Oct 14 '14 13:10 uttarap

Any news about this ? I got the same issue.

mrtnjln avatar Apr 01 '15 08:04 mrtnjln

No, I found no resolution to this. So I am just going to let it be for now.

uttarap avatar Apr 01 '15 13:04 uttarap

+1 happens in IE11

k-makarov avatar Apr 03 '15 09:04 k-makarov

I have a similar issue where the UI-Masked field in my form is being focused automatically. This only happens in IE.

conner-fallone avatar Apr 21 '15 11:04 conner-fallone

Same issue here!

mveenstra avatar Apr 29 '15 21:04 mveenstra

Same issue here :(

gvlekke avatar May 07 '15 14:05 gvlekke

Same happens to me IE 10 and IE 11

asadighi avatar Jun 08 '15 18:06 asadighi

I fixed this issue by changing the source code in the following manner. I don't have time at the moment if nobody fixes it by then, I will send a pull request:

   function getCaretPosition(input){
        if (!input) return 0;
        if (input.selectionStart !== undefined) {
          return input.selectionStart;
        } else if (document.selection) {
            if ($(input).is(':focus')) {
                // Curse you IE
                input.focus();
                var selection = document.selection.createRange();
                selection.moveStart('character', input.value ? -input.value.length : 0);
                return selection.text.length;
            }
            return 0;
        }
        return 0;
      }

      function setCaretPosition(input, pos){
        if (!input) return 0;
        if (input.offsetWidth === 0 || input.offsetHeight === 0) {
          return; // Input's hidden
        }
        if (input.setSelectionRange) {
            if ($(input).is(':focus')) {
                input.focus();
                input.setSelectionRange(pos, pos);
            }
        }
        else if (input.createTextRange) {
            // Curse you IE
            if ($(input).is(':focus')) {
                var range = input.createTextRange();
                range.collapse(true);
                range.moveEnd('character', pos);
                range.moveStart('character', pos);
                range.select();
            }
        }
      }

capture

asadighi avatar Jun 08 '15 20:06 asadighi

I am having this same problem. Please send that pull request :)

kellyprankin avatar Jun 15 '15 20:06 kellyprankin

I am having this is problem too. I tested this fix Applying ui-mask on multiple fields on a form sets focus … on IE 11. Fix is working OK.

megion avatar Jun 29 '15 09:06 megion

closed by #415

PowerKiKi avatar Jun 30 '15 03:06 PowerKiKi

This fix does not work on Chrome it randomly lose focus while typing. Maybe if you have another directive attached with ui-mask.

bhushangahire avatar Aug 02 '16 18:08 bhushangahire