mathiasbynens / jquery-placeholder

A jQuery plugin that enables HTML5 placeholder behavior for browsers that aren’t trying hard enough yet
https://mths.be/placeholder
MIT License
3.98k stars 1.34k forks source link

Password type inputs are focused on submit #226

Closed goodforenergy closed 9 years ago

goodforenergy commented 9 years ago

I have a form on which I am performing client side validation on submit (so as not to progress with the submit if there are issues). I have noticed that the password type input on the form gains focus on submit in browsers where the placeholder plugin is active. You can see this briefly on your demo page (before the submit actually happens), but I have made a fiddle for clarification.

Just press the submit button to reproduce the issue.

amerikan commented 9 years ago

I'm able to duplicate only if the password field is left empty. I have not fully looked into this, but I think the problem arises from here:

$(function() {
    // Look for forms
    $(document).delegate('form', 'submit.placeholder', function() {
        // Clear the placeholder values so they don't get submitted
        var $inputs = $('.placeholder', this).each(clearPlaceholder);
        setTimeout(function() {
            $inputs.each(setPlaceholder);
        }, 10);
    });
});

When submitting a form it'll call the setPlaceholder method and if you look inside that method you'll see that it sets focus to fields.

amerikan commented 9 years ago

Also this https://github.com/mathiasbynens/jquery-placeholder/issues/218 is probably a related if not the same issue.

shaneparsons commented 9 years ago

+1

yangkennyk commented 9 years ago

+1 . when there are multiple password fields, the placeholder text is filling the password input field when submitting an empty form for ie9 and below.

Alex1990 commented 9 years ago

I've come cross this bug and fixed it in #259. The previous set hook and clearPlaceholder are written with bugs. You can check the demo after fixing: http://alex1990.github.io/misc/placeholder-polyfill-test/placeholder-polyfill-test.html.

amerikan commented 9 years ago

Should be fixed in latest version.