Commit 0245c7e1 by Will Daly

Use 'defaultValue' instead of 'default' in the form description. Fix an error…

Use 'defaultValue' instead of 'default' in the form description.  Fix an error that would cause the login and password reset pages to not load correctly.
parent 33f0e92d
...@@ -103,7 +103,7 @@ class FormDescription(object): ...@@ -103,7 +103,7 @@ class FormDescription(object):
} }
OVERRIDE_FIELD_PROPERTIES = [ OVERRIDE_FIELD_PROPERTIES = [
"label", "type", "default", "placeholder", "label", "type", "defaultValue", "placeholder",
"instructions", "required", "restrictions", "instructions", "required", "restrictions",
"options" "options"
] ]
...@@ -172,7 +172,7 @@ class FormDescription(object): ...@@ -172,7 +172,7 @@ class FormDescription(object):
"name": name, "name": name,
"label": label, "label": label,
"type": field_type, "type": field_type,
"default": default, "defaultValue": default,
"placeholder": placeholder, "placeholder": placeholder,
"instructions": instructions, "instructions": instructions,
"required": required, "required": required,
...@@ -217,7 +217,7 @@ class FormDescription(object): ...@@ -217,7 +217,7 @@ class FormDescription(object):
{ {
"name": "cheese_or_wine", "name": "cheese_or_wine",
"label": "Cheese or Wine?", "label": "Cheese or Wine?",
"default": "cheese", "defaultValue": "cheese",
"type": "select", "type": "select",
"required": True, "required": True,
"placeholder": "", "placeholder": "",
...@@ -231,7 +231,7 @@ class FormDescription(object): ...@@ -231,7 +231,7 @@ class FormDescription(object):
{ {
"name": "comments", "name": "comments",
"label": "comments", "label": "comments",
"default": "", "defaultValue": "",
"type": "text", "type": "text",
"required": False, "required": False,
"placeholder": "Any comments?", "placeholder": "Any comments?",
...@@ -275,6 +275,11 @@ class FormDescription(object): ...@@ -275,6 +275,11 @@ class FormDescription(object):
if "field_type" in kwargs: if "field_type" in kwargs:
kwargs["type"] = kwargs["field_type"] kwargs["type"] = kwargs["field_type"]
# Transform kwarg "default" to "defaultValue", since "default"
# is a reserved word in JavaScript
if "default" in kwargs:
kwargs["defaultValue"] = kwargs["default"]
self._field_overrides[field_name].update({ self._field_overrides[field_name].update({
property_name: property_value property_name: property_value
for property_name, property_value in kwargs.iteritems() for property_name, property_value in kwargs.iteritems()
......
...@@ -98,7 +98,7 @@ class FormDescriptionTest(TestCase): ...@@ -98,7 +98,7 @@ class FormDescriptionTest(TestCase):
"name": "name", "name": "name",
"label": "label", "label": "label",
"type": "text", "type": "text",
"default": "default", "defaultValue": "default",
"placeholder": "placeholder", "placeholder": "placeholder",
"instructions": "instructions", "instructions": "instructions",
"required": True, "required": True,
......
...@@ -587,7 +587,7 @@ class LoginSessionViewTest(ApiTestCase): ...@@ -587,7 +587,7 @@ class LoginSessionViewTest(ApiTestCase):
self.assertEqual(form_desc["fields"], [ self.assertEqual(form_desc["fields"], [
{ {
"name": "email", "name": "email",
"default": "", "defaultValue": "",
"type": "text", "type": "text",
"required": True, "required": True,
"label": "E-mail", "label": "E-mail",
...@@ -600,7 +600,7 @@ class LoginSessionViewTest(ApiTestCase): ...@@ -600,7 +600,7 @@ class LoginSessionViewTest(ApiTestCase):
}, },
{ {
"name": "password", "name": "password",
"default": "", "defaultValue": "",
"type": "password", "type": "password",
"required": True, "required": True,
"label": "Password", "label": "Password",
...@@ -613,7 +613,7 @@ class LoginSessionViewTest(ApiTestCase): ...@@ -613,7 +613,7 @@ class LoginSessionViewTest(ApiTestCase):
}, },
{ {
"name": "remember", "name": "remember",
"default": False, "defaultValue": False,
"type": "checkbox", "type": "checkbox",
"required": False, "required": False,
"label": "Remember me", "label": "Remember me",
...@@ -746,7 +746,7 @@ class RegistrationViewTest(ApiTestCase): ...@@ -746,7 +746,7 @@ class RegistrationViewTest(ApiTestCase):
no_extra_fields_setting, no_extra_fields_setting,
{ {
u"name": u"email", u"name": u"email",
u"default": u"", u"defaultValue": u"",
u"type": u"text", u"type": u"text",
u"required": True, u"required": True,
u"label": u"E-mail", u"label": u"E-mail",
...@@ -763,7 +763,7 @@ class RegistrationViewTest(ApiTestCase): ...@@ -763,7 +763,7 @@ class RegistrationViewTest(ApiTestCase):
no_extra_fields_setting, no_extra_fields_setting,
{ {
u"name": u"name", u"name": u"name",
u"default": u"", u"defaultValue": u"",
u"type": u"text", u"type": u"text",
u"required": True, u"required": True,
u"label": u"Full Name", u"label": u"Full Name",
...@@ -779,7 +779,7 @@ class RegistrationViewTest(ApiTestCase): ...@@ -779,7 +779,7 @@ class RegistrationViewTest(ApiTestCase):
no_extra_fields_setting, no_extra_fields_setting,
{ {
u"name": u"username", u"name": u"username",
u"default": u"", u"defaultValue": u"",
u"type": u"text", u"type": u"text",
u"required": True, u"required": True,
u"label": u"Public Username", u"label": u"Public Username",
...@@ -796,7 +796,7 @@ class RegistrationViewTest(ApiTestCase): ...@@ -796,7 +796,7 @@ class RegistrationViewTest(ApiTestCase):
no_extra_fields_setting, no_extra_fields_setting,
{ {
u"name": u"password", u"name": u"password",
u"default": u"", u"defaultValue": u"",
u"type": u"text", u"type": u"text",
u"required": True, u"required": True,
u"label": u"Password", u"label": u"Password",
...@@ -822,7 +822,7 @@ class RegistrationViewTest(ApiTestCase): ...@@ -822,7 +822,7 @@ class RegistrationViewTest(ApiTestCase):
no_extra_fields_setting, no_extra_fields_setting,
{ {
"name": "password", "name": "password",
"default": "", "defaultValue": "",
"type": "hidden", "type": "hidden",
"required": False, "required": False,
"label": "", "label": "",
...@@ -837,7 +837,7 @@ class RegistrationViewTest(ApiTestCase): ...@@ -837,7 +837,7 @@ class RegistrationViewTest(ApiTestCase):
no_extra_fields_setting, no_extra_fields_setting,
{ {
u"name": u"email", u"name": u"email",
u"default": u"bob@example.com", u"defaultValue": u"bob@example.com",
u"type": u"text", u"type": u"text",
u"required": True, u"required": True,
u"label": u"E-mail", u"label": u"E-mail",
...@@ -855,7 +855,7 @@ class RegistrationViewTest(ApiTestCase): ...@@ -855,7 +855,7 @@ class RegistrationViewTest(ApiTestCase):
no_extra_fields_setting, no_extra_fields_setting,
{ {
u"name": u"name", u"name": u"name",
u"default": u"Bob", u"defaultValue": u"Bob",
u"type": u"text", u"type": u"text",
u"required": True, u"required": True,
u"label": u"Full Name", u"label": u"Full Name",
...@@ -872,7 +872,7 @@ class RegistrationViewTest(ApiTestCase): ...@@ -872,7 +872,7 @@ class RegistrationViewTest(ApiTestCase):
no_extra_fields_setting, no_extra_fields_setting,
{ {
u"name": u"username", u"name": u"username",
u"default": u"Bob123", u"defaultValue": u"Bob123",
u"type": u"text", u"type": u"text",
u"required": True, u"required": True,
u"label": u"Public Username", u"label": u"Public Username",
...@@ -890,7 +890,7 @@ class RegistrationViewTest(ApiTestCase): ...@@ -890,7 +890,7 @@ class RegistrationViewTest(ApiTestCase):
{"level_of_education": "optional"}, {"level_of_education": "optional"},
{ {
"name": "level_of_education", "name": "level_of_education",
"default": "", "defaultValue": "",
"type": "select", "type": "select",
"required": False, "required": False,
"label": "Highest Level of Education Completed", "label": "Highest Level of Education Completed",
...@@ -917,7 +917,7 @@ class RegistrationViewTest(ApiTestCase): ...@@ -917,7 +917,7 @@ class RegistrationViewTest(ApiTestCase):
{"gender": "optional"}, {"gender": "optional"},
{ {
"name": "gender", "name": "gender",
"default": "", "defaultValue": "",
"type": "select", "type": "select",
"required": False, "required": False,
"label": "Gender", "label": "Gender",
...@@ -945,7 +945,7 @@ class RegistrationViewTest(ApiTestCase): ...@@ -945,7 +945,7 @@ class RegistrationViewTest(ApiTestCase):
{"year_of_birth": "optional"}, {"year_of_birth": "optional"},
{ {
"name": "year_of_birth", "name": "year_of_birth",
"default": "", "defaultValue": "",
"type": "select", "type": "select",
"required": False, "required": False,
"label": "Year of Birth", "label": "Year of Birth",
...@@ -961,7 +961,7 @@ class RegistrationViewTest(ApiTestCase): ...@@ -961,7 +961,7 @@ class RegistrationViewTest(ApiTestCase):
{"mailing_address": "optional"}, {"mailing_address": "optional"},
{ {
"name": "mailing_address", "name": "mailing_address",
"default": "", "defaultValue": "",
"type": "textarea", "type": "textarea",
"required": False, "required": False,
"label": "Mailing Address", "label": "Mailing Address",
...@@ -976,7 +976,7 @@ class RegistrationViewTest(ApiTestCase): ...@@ -976,7 +976,7 @@ class RegistrationViewTest(ApiTestCase):
{"goals": "optional"}, {"goals": "optional"},
{ {
"name": "goals", "name": "goals",
"default": "", "defaultValue": "",
"type": "textarea", "type": "textarea",
"required": False, "required": False,
"label": "Please share with us your reasons for registering with edX", "label": "Please share with us your reasons for registering with edX",
...@@ -991,7 +991,7 @@ class RegistrationViewTest(ApiTestCase): ...@@ -991,7 +991,7 @@ class RegistrationViewTest(ApiTestCase):
{"city": "optional"}, {"city": "optional"},
{ {
"name": "city", "name": "city",
"default": "", "defaultValue": "",
"type": "text", "type": "text",
"required": False, "required": False,
"label": "City", "label": "City",
...@@ -1014,7 +1014,7 @@ class RegistrationViewTest(ApiTestCase): ...@@ -1014,7 +1014,7 @@ class RegistrationViewTest(ApiTestCase):
{ {
"label": "Country", "label": "Country",
"name": "country", "name": "country",
"default": "", "defaultValue": "",
"type": "select", "type": "select",
"required": True, "required": True,
"placeholder": "", "placeholder": "",
...@@ -1034,7 +1034,7 @@ class RegistrationViewTest(ApiTestCase): ...@@ -1034,7 +1034,7 @@ class RegistrationViewTest(ApiTestCase):
{ {
"label": "I agree to the <a href=\"https://www.test.com/honor\">Terms of Service and Honor Code</a>", "label": "I agree to the <a href=\"https://www.test.com/honor\">Terms of Service and Honor Code</a>",
"name": "honor_code", "name": "honor_code",
"default": False, "defaultValue": False,
"type": "checkbox", "type": "checkbox",
"required": True, "required": True,
"placeholder": "", "placeholder": "",
...@@ -1051,7 +1051,7 @@ class RegistrationViewTest(ApiTestCase): ...@@ -1051,7 +1051,7 @@ class RegistrationViewTest(ApiTestCase):
{ {
"label": "I agree to the <a href=\"/honor\">Terms of Service and Honor Code</a>", "label": "I agree to the <a href=\"/honor\">Terms of Service and Honor Code</a>",
"name": "honor_code", "name": "honor_code",
"default": False, "defaultValue": False,
"type": "checkbox", "type": "checkbox",
"required": True, "required": True,
"placeholder": "", "placeholder": "",
...@@ -1074,7 +1074,7 @@ class RegistrationViewTest(ApiTestCase): ...@@ -1074,7 +1074,7 @@ class RegistrationViewTest(ApiTestCase):
{ {
"label": "I agree to the <a href=\"https://www.test.com/honor\">Honor Code</a>", "label": "I agree to the <a href=\"https://www.test.com/honor\">Honor Code</a>",
"name": "honor_code", "name": "honor_code",
"default": False, "defaultValue": False,
"type": "checkbox", "type": "checkbox",
"required": True, "required": True,
"placeholder": "", "placeholder": "",
...@@ -1089,7 +1089,7 @@ class RegistrationViewTest(ApiTestCase): ...@@ -1089,7 +1089,7 @@ class RegistrationViewTest(ApiTestCase):
{ {
"label": "I agree to the <a href=\"https://www.test.com/tos\">Terms of Service</a>", "label": "I agree to the <a href=\"https://www.test.com/tos\">Terms of Service</a>",
"name": "terms_of_service", "name": "terms_of_service",
"default": False, "defaultValue": False,
"type": "checkbox", "type": "checkbox",
"required": True, "required": True,
"placeholder": "", "placeholder": "",
...@@ -1108,7 +1108,7 @@ class RegistrationViewTest(ApiTestCase): ...@@ -1108,7 +1108,7 @@ class RegistrationViewTest(ApiTestCase):
{ {
"label": "I agree to the <a href=\"/honor\">Honor Code</a>", "label": "I agree to the <a href=\"/honor\">Honor Code</a>",
"name": "honor_code", "name": "honor_code",
"default": False, "defaultValue": False,
"type": "checkbox", "type": "checkbox",
"required": True, "required": True,
"placeholder": "", "placeholder": "",
...@@ -1123,7 +1123,7 @@ class RegistrationViewTest(ApiTestCase): ...@@ -1123,7 +1123,7 @@ class RegistrationViewTest(ApiTestCase):
{ {
"label": "I agree to the <a href=\"/tos\">Terms of Service</a>", "label": "I agree to the <a href=\"/tos\">Terms of Service</a>",
"name": "terms_of_service", "name": "terms_of_service",
"default": False, "defaultValue": False,
"type": "checkbox", "type": "checkbox",
"required": True, "required": True,
"placeholder": "", "placeholder": "",
......
...@@ -32,7 +32,8 @@ var edx = edx || {}; ...@@ -32,7 +32,8 @@ var edx = edx || {};
name: 'email', name: 'email',
required: true, required: true,
type: 'email', type: 'email',
restrictions: [] restrictions: [],
defaultValue: ''
}]); }]);
this.tpl = $(this.tpl).html(); this.tpl = $(this.tpl).html();
......
...@@ -88,9 +88,6 @@ var edx = edx || {}; ...@@ -88,9 +88,6 @@ var edx = edx || {};
len = data.length, len = data.length,
fieldTpl = this.fieldTpl; fieldTpl = this.fieldTpl;
for ( i=0; i<len; i++ ) { for ( i=0; i<len; i++ ) {
// "default" is reserved in JavaScript
data[i].value = data[i]["default"];
html.push( _.template( fieldTpl, $.extend( data[i], { html.push( _.template( fieldTpl, $.extend( data[i], {
form: 'register' form: 'register'
}) ) ); }) ) );
......
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
<% if ( restrictions.min_length ) { %> minlength="<%= restrictions.min_length %>"<% } %> <% if ( restrictions.min_length ) { %> minlength="<%= restrictions.min_length %>"<% } %>
<% if ( restrictions.max_length ) { %> maxlength="<%= restrictions.max_length %>"<% } %> <% if ( restrictions.max_length ) { %> maxlength="<%= restrictions.max_length %>"<% } %>
<% if ( required ) { %> required<% } %> <% if ( required ) { %> required<% } %>
value="<%- value %>" value="<%- defaultValue %>"
/> />
<% } %> <% } %>
......
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