Skip to content

Commit

Permalink
Fix issue causing new forms to submit placeholder values
Browse files Browse the repository at this point in the history
  • Loading branch information
James Allardice committed Oct 27, 2012
1 parent 85c7f41 commit 3a25241
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 9 deletions.
17 changes: 17 additions & 0 deletions Placeholders.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ var Placeholders = (function () {
numInputs = inputs.length,
num = numInputs + textareas.length,
i,
form,
element,
oldPlaceholder,
newPlaceholder;
Expand Down Expand Up @@ -263,6 +264,22 @@ var Placeholders = (function () {

//If the current placeholder data-* attribute has no value the element wasn't present in the DOM when event handlers were bound, so bind them now
if (!oldPlaceholder) {
//If the element has a containing form bind to the submit event so we can prevent placeholder values being submitted as actual values
if (element.form) {

//Get a reference to the containing form element (if present)
form = element.form;

//The placeholdersubmit data-* attribute is set if this form has already been dealt with
if (!form.getAttribute("data-placeholdersubmit")) {

//The placeholdersubmit attribute wasn't set, so attach a submit event handler
addEventListener(form, "submit", submitHandler);

//Set the placeholdersubmit attribute so we don't repeatedly bind event handlers to this form element
form.setAttribute("data-placeholdersubmit", "true");
}
}
addEventListeners(element);
}

Expand Down
15 changes: 8 additions & 7 deletions Placeholders.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Placeholders.js is licensed under the [MIT License](http://en.wikipedia.org/wiki
- Works properly for `input` elements of the **`password` type** in all browsers except Internet Explorer 8 and below, in which the placeholder appears as masked text
- Wide range of browsers supported, **including IE6**
- **No dependencies** (so no need to include jQuery, unlike most placeholder polyfill scripts)
- All of the above in just 4kB when minified, and about **1kB when gzipped**!
- All of the above in just 5kB when minified, and about **1kB when gzipped**!

##How do I use it?

Expand Down Expand Up @@ -83,4 +83,4 @@ Do you use some obscure browser that doesn't have native `placeholder` attribute

You can download the repository at various states from the [tags page](https://github.com/jamesallardice/Placeholders.js/tags), or with the following links:

[Current version (1.1)](https://github.com/jamesallardice/Placeholders.js/zipball/v1.1) | [1.0](https://github.com/jamesallardice/Placeholders.js/zipball/v1.0)
[Current version (1.2)](https://github.com/jamesallardice/Placeholders.js/zipball/v1.2) | [1.1](https://github.com/jamesallardice/Placeholders.js/zipball/v1.1) | [1.0](https://github.com/jamesallardice/Placeholders.js/zipball/v1.0)

0 comments on commit 3a25241

Please sign in to comment.