Commit daeb2cc1 by Diana Huang

Fix registration fields bugs.

parent 70dc3359
...@@ -113,6 +113,8 @@ ...@@ -113,6 +113,8 @@
} }
} }
this.hasOptionalFields = optionalFields.length > 0;
html = this.renderFields(requiredFields, 'required-fields'); html = this.renderFields(requiredFields, 'required-fields');
html.push.apply(html, this.renderFields(optionalFields, 'optional-fields')); html.push.apply(html, this.renderFields(optionalFields, 'optional-fields'));
...@@ -158,22 +160,16 @@ ...@@ -158,22 +160,16 @@
}, },
postRender: function() { postRender: function() {
var inputs = [ var inputs = this.$('.form-field'),
this.$('#register-name'),
this.$('#register-email'),
this.$('#register-username'),
this.$('#register-password'),
this.$('#register-country')
],
inputTipSelectors = ['tip error', 'tip tip-input'], inputTipSelectors = ['tip error', 'tip tip-input'],
inputTipSelectorsHidden = ['tip error hidden', 'tip tip-input hidden'], inputTipSelectorsHidden = ['tip error hidden', 'tip tip-input hidden'],
onInputFocus = function() { onInputFocus = function() {
// Apply on focus styles to input // Apply on focus styles to input
$(this).prev('label').addClass('focus-in') $(this).find('label').addClass('focus-in')
.removeClass('focus-out'); .removeClass('focus-out');
// Show each input tip // Show each input tip
$(this).siblings().each(function() { $(this).children().each(function() {
if (inputTipSelectorsHidden.includes($(this).attr('class'))) { if (inputTipSelectorsHidden.includes($(this).attr('class'))) {
$(this).removeClass('hidden'); $(this).removeClass('hidden');
} }
...@@ -182,12 +178,12 @@ ...@@ -182,12 +178,12 @@
onInputFocusOut = function() { onInputFocusOut = function() {
// If input has no text apply focus out styles // If input has no text apply focus out styles
if ($(this).val().length === 0) { if ($(this).val().length === 0) {
$(this).prev('label').addClass('focus-out') $(this).find('label').addClass('focus-out')
.removeClass('focus-in'); .removeClass('focus-in');
} }
// Hide each input tip // Hide each input tip
$(this).siblings().each(function() { $(this).children().each(function() {
if (inputTipSelectors.includes($(this).attr('class'))) { if (inputTipSelectors.includes($(this).attr('class'))) {
$(this).addClass('hidden'); $(this).addClass('hidden');
} }
...@@ -196,12 +192,12 @@ ...@@ -196,12 +192,12 @@
handleInputBehavior = function(input) { handleInputBehavior = function(input) {
// Initially put label in input // Initially put label in input
if (input.val().length === 0) { if (input.val().length === 0) {
input.prev('label').addClass('focus-out') input.find('label').addClass('focus-out')
.removeClass('focus-in'); .removeClass('focus-in');
} }
// Initially hide each input tip // Initially hide each input tip
input.siblings().each(function() { input.children().each(function() {
if (inputTipSelectors.includes($(this).attr('class'))) { if (inputTipSelectors.includes($(this).attr('class'))) {
$(this).addClass('hidden'); $(this).addClass('hidden');
} }
...@@ -211,14 +207,19 @@ ...@@ -211,14 +207,19 @@
input.focusout(onInputFocusOut); input.focusout(onInputFocusOut);
}, },
handleAutocomplete = function() { handleAutocomplete = function() {
inputs.forEach(function(input) { $(inputs).each(function() {
if (input.val().length === 0 && !input.is(':-webkit-autofill')) { var $input = $(this),
input.prev('label').addClass('focus-out') isCheckbox = $input.attr('class').indexOf('checkbox') !== -1;
if (!isCheckbox) {
if ($input.val().length === 0 && !$input.is(':-webkit-autofill')) {
$input.find('label').addClass('focus-out')
.removeClass('focus-in'); .removeClass('focus-in');
} else { } else {
input.prev('label').addClass('focus-in') $input.find('label').addClass('focus-in')
.removeClass('focus-out'); .removeClass('focus-out');
} }
}
}); });
}; };
...@@ -234,6 +235,9 @@ ...@@ -234,6 +235,9 @@
// improvement so that we don't have to show all the optional fields. // improvement so that we don't have to show all the optional fields.
// xss-lint: disable=javascript-jquery-insert-into-target // xss-lint: disable=javascript-jquery-insert-into-target
$('.checkbox-optional_fields_toggle').insertBefore('.optional-fields'); $('.checkbox-optional_fields_toggle').insertBefore('.optional-fields');
if (!this.hasOptionalFields) {
$('.checkbox-optional_fields_toggle').addClass('hidden');
}
// xss-lint: disable=javascript-jquery-insert-into-target // xss-lint: disable=javascript-jquery-insert-into-target
$('.checkbox-honor_code').insertAfter('.optional-fields'); $('.checkbox-honor_code').insertAfter('.optional-fields');
...@@ -243,10 +247,14 @@ ...@@ -243,10 +247,14 @@
ev.preventDefault(); ev.preventDefault();
window.open($(this).attr('href'), $(this).attr('target')); window.open($(this).attr('href'), $(this).attr('target'));
}); });
$('#register-country option:first').html(''); $('.form-field').each(function() {
inputs.forEach(function(input) { $(this).find('option:first').html('');
if (input.length > 0) { });
handleInputBehavior(input); $(inputs).each(function() {
var $input = $(this),
isCheckbox = $input.attr('class').indexOf('checkbox') !== -1;
if ($input.length > 0 && !isCheckbox) {
handleInputBehavior($input);
} }
}); });
setTimeout(handleAutocomplete, 1000); setTimeout(handleAutocomplete, 1000);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment