Question

I am working on a login form on which I have added "placeholders" with Mootools OverText (* http://mootools.net/docs/more/Forms/OverText , http://mootools.net/demos/?demo=Enhanced-Form ).

The problem is that the browsers is autocompleting the fields with email/password and they are showing under the OverText. Is there any way I can make the overtext not show when the fields are filled by the browser? (*I would like to keep the autocomplete ON)

*When the browser is autocompleting the fields the OverText is showing over the email/password:

When the browser is autocompleting the fields

**Normal view of the fields with OverText:

normal view of the fields with OverText

<form id="user_form_login" action="/login">
    <div id="email-wrapper" class="form-wrapper">
      <div id="email-element" class="form-element">
        <input type="email" name="email" id="email" value="" tabindex="1" class="text" autocomplete="off" title="<?php echo $this->translate('Email Address'); ?>">
      </div>
    </div>

    <div id="password-wrapper" class="form-wrapper">
      <div id="password-element" class="form-element">
        <input type="password" name="password" id="password" value="" tabindex="2" title="<?php echo $this->translate('Password'); ?>">
      </div>
    </div>
</form>

<script type="text/javascript">
window.addEvent('domready', function(){
  var LoginForm = $('user_form_login');
  LoginForm.getElements('[type=email], [type=password]').each(function(el){
    new OverText(el);
  });
});
</script>
Was it helpful?

Solution

Try this:

<script type="text/javascript">
window.addEvent('domready', function(){
  var LoginForm = $('user_form_login');
  LoginForm.getElements('[type=email], [type=password]').each(function(el){
    new OverText(el);
  });
  // *** New part ***
  LoginForm.getElements('[type=email], [type=password]').addEvent('change', function () {
        this.getNext('label').set('text', '');
    });
});
</script>

EDIT:
(Another alternative since its difficult to detect auto-fill)

var All_El = LoginForm.getElements('[type=email], [type=password]');
var re_check = setInterval(function () {
    All_El.each(function (el) {
        if (el.value != '') {
            el.getNext('label').set('text', '');
        }
    });
}, 400);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top