Skip to content
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

Hi , I patched simple.js to change type="password" to type="text" on placeholders #17

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
14 changes: 14 additions & 0 deletions src/simple.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
// Author: James Brumond <[email protected]> (http://www.jbrumond.me)
//

// Patched by Francesco Munafò to automatically transform password fields to text fields when a placeholder is used

(function(window, document, undefined) {

// Don't run the polyfill if it isn't needed
Expand Down Expand Up @@ -131,14 +133,26 @@

function checkPlaceholder() {
if (elem.value) {

/* FRANCESCOMM START */
if(elem.wasPassword === true) {elem.type = 'password';}
/* FRANCESCOMM END */

hidePlaceholder();
} else {
/* FRANCESCOMM START */
if(elem.type === 'password') {elem.wasPassword=true; elem.type = 'text';}
/* FRANCESCOMM END */

showPlaceholder();
}
}

function showPlaceholder() {
if (! elem.__placeholder && ! elem.value) {
/* FRANCESCOMM START */
if(elem.type === 'password') {elem.wasPassword=true; elem.type = 'text';}
/* FRANCESCOMM END */
doShowPlaceholder();
}
}
Expand Down
27 changes: 27 additions & 0 deletions src/simple_clean_submit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@

// This is a demo script to remove fake input placeholders (value="") from inputs on submit
// Or you can do it sever side
// francescomm

$(document).on("submit",function(e) {


// remove placeholders from all fields before submitting

$("input,textarea").each(function() {
var value=$(this).val();
if($(this).val()!=="" && $(this).val()===$(this).attr("placeholder")) $(this).val("");
});


// in case submit fails, restore placeholders, after 1 second

setTimeout(function() {
$("input,textarea").each(function() {
if($(this).val()==="" && $(this).attr("placeholder")!=="") $(this).val($(this).attr("placeholder"));
});
},1000);

//e.preventDefault(); // don't stop, (uncomment for testing) let the submitting go on

})