Skip to content
This repository was archived by the owner on Jan 24, 2019. It is now read-only.

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

Closed
uttarap opened this issue Oct 14, 2014 · 12 comments
Labels

Comments

@uttarap
Copy link

uttarap commented Oct 14, 2014

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?

@mrtnjln
Copy link

mrtnjln commented Apr 1, 2015

Any news about this ? I got the same issue.

@uttarap
Copy link
Author

uttarap commented Apr 1, 2015

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

@k-makarov
Copy link

+1 happens in IE11

@conner-fallone
Copy link

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

@mveenstra
Copy link

Same issue here!

@gvlekke
Copy link

gvlekke commented May 7, 2015

Same issue here :(

@asadighi
Copy link
Contributor

asadighi commented Jun 8, 2015

Same happens to me IE 10 and IE 11

@asadighi
Copy link
Contributor

asadighi commented Jun 8, 2015

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

@kellyprankin
Copy link

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

asadighi added a commit to asadighi/ui-utils that referenced this issue Jun 15, 2015
…ets focus on the last masked input box automatically
asadighi added a commit to asadighi/ui-utils that referenced this issue Jun 15, 2015
…ets focus on the last masked input box automatically
@megion
Copy link

megion commented Jun 29, 2015

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.

PowerKiKi added a commit that referenced this issue Jun 30, 2015
[Fix] #317:  ui-mask sets focus on the last masked input box
@PowerKiKi
Copy link
Contributor

closed by #415

@bhushangahire
Copy link

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests