Skip to content

Mess with maxlength only if specified #56

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 29, 2013
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,12 @@
elem.className = elem.className.replace(classNameRegExp, "");

// Restore the maxlength value
maxLength = elem.getAttribute(ATTR_MAXLENGTH);
if (maxLength) {
elem.setAttribute("maxLength", maxLength);
elem.removeAttribute(ATTR_MAXLENGTH);
if (elem.hasAttribute(ATTR_MAXLENGTH)) {
maxLength = elem.getAttribute(ATTR_MAXLENGTH);
if (maxLength > 0) {
elem.setAttribute("maxLength", maxLength);
elem.removeAttribute(ATTR_MAXLENGTH);
}
}

// If the polyfill has changed the type of the element we need to change it back
Expand All @@ -113,10 +115,12 @@
elem.className += " " + placeholderClassName;

// Store and remove the maxlength value
maxLength = elem.getAttribute(ATTR_MAXLENGTH);
if (!maxLength) {
elem.setAttribute(ATTR_MAXLENGTH, elem.maxLength);
elem.removeAttribute("maxLength");
if (elem.hasAttribute("maxLength")) {
maxLength = elem.getAttribute("maxLength") || elem.maxLength;
if (parseInt(maxLength, 10) > 0) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is parseInt needed here? The > operator should coerce its operands to Number. If it is needed, why is it not needed on line 91?

elem.setAttribute(ATTR_MAXLENGTH, maxLength);
elem.removeAttribute("maxLength");
}
}

// If the type of element needs to change, change it (e.g. password inputs)
Expand Down