Skip to content

Instantly share code, notes, and snippets.

@kremalicious
Last active May 11, 2017 12:00
Show Gist options
  • Save kremalicious/72e66c5918476fb18ab902c5bc431ffa to your computer and use it in GitHub Desktop.
Save kremalicious/72e66c5918476fb18ab902c5bc431ffa to your computer and use it in GitHub Desktop.
Removes the need for username input upon signup for 3scale-based developer portals
// Tactic: highjack form submission, then make value of username field the same as email field, then submit the form
document.addEventListener('DOMContentLoaded', function() {
// First, hide the whole username form row
var style = document.createElement('style'),
css = '#signup_form fieldset:nth-of-type(2) .form-group:nth-child(2) { display: none; }';
style.type = 'text/css';
if (style.styleSheet){
style.styleSheet.cssText = css;
} else {
style.appendChild(document.createTextNode(css));
}
document.head.appendChild(style);
// Then, move on to input value cloning
var form = document.getElementById('signup_form'),
email = document.getElementById('account_user_email'),
username = document.getElementById('account_user_username'),
button = document.getElementById('signup_button');
function submitForm() {
// Make username same as email, but strip the @ part
username.value = email.value.match(/^([^@]*)@/)[1];
form.submit();
}
// highjack button click
button.addEventListener('click', function(event) {
event.preventDefault();
submitForm();
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment