diff --git a/src/simple.js b/src/simple.js index 218d874..68399b4 100644 --- a/src/simple.js +++ b/src/simple.js @@ -4,6 +4,8 @@ // Author: James Brumond (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 @@ -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(); } } diff --git a/src/simple_clean_submit.js b/src/simple_clean_submit.js new file mode 100644 index 0000000..b9b15ae --- /dev/null +++ b/src/simple_clean_submit.js @@ -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 + + })