Skip to content

Instantly share code, notes, and snippets.

@noahub
Last active December 28, 2023 11:24
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save noahub/65a67b6a32dd5b4d87e3d7fecff79592 to your computer and use it in GitHub Desktop.
Save noahub/65a67b6a32dd5b4d87e3d7fecff79592 to your computer and use it in GitHub Desktop.
Change Form Field Input Types
<script>
window.onload = function() {
//set up input styling
var newStyle;
getInputStyle();
//Use the setType function to update the input type. First parameter is input name, second is the input type.
setType("phone","tel");
setType("email","email");
setType("date","date");
setType("phone","tel");
setType("color","color");
setType("number", "number");
function getInputStyle(){
var formId = '#'+$('.lp-pom-form').attr("id");
var styleClass1 = '.lp-pom-form-field input[type="text"]';
var styleClass2 = ".lp-pom-form-field input.text";
var legacyStyle = 'position: absolute; left: 0; margin-bottom: 12px;';
//Get basic field styling
var stylesheet = document.styleSheets[0];
newStyle = "";
var ruleLength = stylesheet.cssRules.length;
for(var i=0;i<ruleLength;i++){
if(stylesheet.cssRules[i].selectorText == formId+" "+styleClass1){
newStyle += document.styleSheets[0].cssRules[i].style.cssText;
}
if(stylesheet.cssRules[i].selectorText == formId+" "+styleClass2){
newStyle += document.styleSheets[0].cssRules[i].style.cssText;
}
}
newStyle += legacyStyle;
}
function setType(id, newType){
document.getElementById(id).type = newType;
document.getElementById(id).style.cssText = newStyle;
}
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment