Unverified Commit cd700231 by Douglas Hall Committed by GitHub

Merge pull request #16861 from edx/douglashall/ENT-796

Fix optional registration fields toggle.
parents 9b10dd70 ede8ee4a
...@@ -213,7 +213,12 @@ ...@@ -213,7 +213,12 @@
} }
] ]
}; };
var createRegisterView = function(that) { var createRegisterView = function(that, formFields) {
var fields = formFields;
if (typeof fields === 'undefined') {
fields = FORM_DESCRIPTION.fields;
}
// Initialize the register model // Initialize the register model
model = new RegisterModel({}, { model = new RegisterModel({}, {
url: FORM_DESCRIPTION.submit_url, url: FORM_DESCRIPTION.submit_url,
...@@ -222,7 +227,7 @@ ...@@ -222,7 +227,7 @@
// Initialize the register view // Initialize the register view
view = new RegisterView({ view = new RegisterView({
fields: FORM_DESCRIPTION.fields, fields: fields,
model: model, model: model,
thirdPartyAuth: THIRD_PARTY_AUTH, thirdPartyAuth: THIRD_PARTY_AUTH,
platformName: PLATFORM_NAME platformName: PLATFORM_NAME
...@@ -537,6 +542,27 @@ ...@@ -537,6 +542,27 @@
// The iframe has been deleted // The iframe has been deleted
expect($content.find('iframe').length).toEqual(0); expect($content.find('iframe').length).toEqual(0);
}); });
it('displays optional fields toggle', function() {
createRegisterView(this);
expect(view.$('.checkbox-optional_fields_toggle')).toBeVisible();
});
it('hides optional fields toggle when there are no visible optional fields', function() {
createRegisterView(this, [
{
placeholder: '',
name: 'hidden_optional',
label: 'Hidden Optional',
defaultValue: '',
type: 'hidden',
required: false,
instructions: 'Used for testing hidden input fields that are optional.',
restrictions: {}
}
]);
expect(view.$('.checkbox-optional_fields_toggle')).toHaveClass('hidden');
});
}); });
}); });
}).call(this, define || RequireJS.define); }).call(this, define || RequireJS.define);
...@@ -94,27 +94,35 @@ ...@@ -94,27 +94,35 @@
buildForm: function(data) { buildForm: function(data) {
var html = [], var html = [],
i, i,
field,
len = data.length, len = data.length,
requiredFields = [], requiredFields = [],
optionalFields = []; optionalFields = [];
this.fields = data; this.fields = data;
this.hasOptionalFields = false;
for (i = 0; i < len; i++) { for (i = 0; i < len; i++) {
if (data[i].errorMessages) { field = data[i];
if (field.errorMessages) {
// eslint-disable-next-line no-param-reassign // eslint-disable-next-line no-param-reassign
data[i].errorMessages = this.escapeStrings(data[i].errorMessages); field.errorMessages = this.escapeStrings(field.errorMessages);
} }
if (data[i].required) { if (field.required) {
requiredFields.push(data[i]); requiredFields.push(field);
} else { } else {
optionalFields.push(data[i]); if (field.type !== 'hidden') {
// For the purporse of displaying the optional field toggle,
// the form should be considered to have optional fields
// only if all of the optional fields are being rendering as
// input elements that are visible on the page.
this.hasOptionalFields = true;
}
optionalFields.push(field);
} }
} }
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'));
......
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