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

Placeholder text is being submitted with the form #254

Closed ghost closed 9 years ago

ghost commented 9 years ago

I'm using onclick handlers on an image (I know, this is bad code -- it is legacy code I'm stuck with) that submits the page's form. The placeholder shows up perfectly, but when I submit without changing the placeholder text (in my case "Enter your notes...") shows up in the notes section of the form. I've seen similar issues like this, but no good solutions -- please help!

inspire22 commented 9 years ago

I'd been having this issue with IE10/11 lately, and am using this coffeescript as a workaround:

  fix_ie10_placeholder = ->
    return unless navigator.userAgent.match /Trident\/6\.0|Trident.*rv\:11\./ 
    console.log("fixing ie 10/11 placeholder text turbolinks bug")

    $('textarea').each ->
      if $(@).val() == $(@).attr('placeholder')
        $(@).val ''
stukalin commented 9 years ago

Created a pull request for that. https://github.com/mathiasbynens/jquery-placeholder/pull/265 Give it a try, maybe it'd help you.

ghost commented 9 years ago

Thanks -- I'll give it a go and let you know how it works out.

stukalin commented 9 years ago

Ah, was wrong. The timeout should be longer. Like 1000 or even 2000

amerikan commented 9 years ago

Have you tried using the version on latest commit? https://github.com/mathiasbynens/jquery-placeholder/blob/gh-pages/jquery.placeholder.js it's not minimized, but that's the latest and many bugs were fixed.

stukalin commented 9 years ago

Yeah, but this

 setTimeout(function() {
                    $inputs.each(setPlaceholder);
                }, 10);

didn't work for me until I increased this to 1-2 sec

amerikan commented 9 years ago

@inspire22 that should not be the case. The plugin should not even activate on IE 10/11 since those versions already support placeholder attribute natively.

amerikan commented 9 years ago

duplicate of #244