Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
6502eaf7
Commit
6502eaf7
authored
Apr 16, 2015
by
muzaffaryousaf
Committed by
Andy Armstrong
Apr 17, 2015
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
DropDownFieldView should show empty option if model value is unset.
TNL-2022
parent
e50a6416
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
35 additions
and
5 deletions
+35
-5
common/test/acceptance/tests/lms/test_account_settings.py
+1
-1
lms/static/js/spec/views/fields_spec.js
+28
-0
lms/static/js/views/fields.js
+4
-2
lms/templates/fields/field_dropdown.underscore
+2
-2
No files found.
common/test/acceptance/tests/lms/test_account_settings.py
View file @
6502eaf7
...
@@ -318,7 +318,7 @@ class AccountSettingsPageTest(AccountSettingsTestMixin, WebAppTest):
...
@@ -318,7 +318,7 @@ class AccountSettingsPageTest(AccountSettingsTestMixin, WebAppTest):
self
.
_test_dropdown_field
(
self
.
_test_dropdown_field
(
u'country'
,
u'country'
,
u'Country or Region'
,
u'Country or Region'
,
u'
Afghanistan
'
,
u''
,
[
u'Pakistan'
,
u'Palau'
],
[
u'Pakistan'
,
u'Palau'
],
)
)
...
...
lms/static/js/spec/views/fields_spec.js
View file @
6502eaf7
...
@@ -192,6 +192,34 @@ define(['backbone', 'jquery', 'underscore', 'js/common_helpers/ajax_helpers', 'j
...
@@ -192,6 +192,34 @@ define(['backbone', 'jquery', 'underscore', 'js/common_helpers/ajax_helpers', 'j
},
requests
);
},
requests
);
});
});
it
(
"only shows empty option in DropdownFieldView if required is false or model value is not set"
,
function
()
{
requests
=
AjaxHelpers
.
requests
(
this
);
var
editableOptions
=
[
'toggle'
,
'always'
];
_
.
each
(
editableOptions
,
function
(
editable
)
{
var
fieldData
=
FieldViewsSpecHelpers
.
createFieldData
(
FieldViews
.
DropdownFieldView
,
{
title
:
'Drop Down Field'
,
valueAttribute
:
'drop-down'
,
helpMessage
:
'edX drop down'
,
editable
:
editable
,
required
:
true
});
var
view
=
new
FieldViews
.
DropdownFieldView
(
fieldData
).
render
();
expect
(
view
.
modelValueIsSet
()).
toBe
(
false
);
expect
(
view
.
displayValue
()).
toBe
(
''
);
if
(
editable
===
'toggle'
)
{
view
.
showEditMode
(
true
);
}
view
.
$
(
'.u-field-value > select'
).
val
(
FieldViewsSpecHelpers
.
SELECT_OPTIONS
[
0
]).
change
();
expect
(
view
.
fieldValue
()).
toBe
(
FieldViewsSpecHelpers
.
SELECT_OPTIONS
[
0
][
0
]);
AjaxHelpers
.
respondWithNoContent
(
requests
);
if
(
editable
===
'toggle'
)
{
view
.
showEditMode
(
true
);
}
// When server returns success, there should no longer be an empty option.
expect
(
$
(
view
.
$
(
'.u-field-value option'
)[
0
]).
val
()).
toBe
(
'si'
);
});
});
it
(
"correctly renders and updates TextAreaFieldView when editable == never"
,
function
()
{
it
(
"correctly renders and updates TextAreaFieldView when editable == never"
,
function
()
{
var
fieldData
=
FieldViewsSpecHelpers
.
createFieldData
(
FieldViews
.
TextareaFieldView
,
{
var
fieldData
=
FieldViewsSpecHelpers
.
createFieldData
(
FieldViews
.
TextareaFieldView
,
{
title
:
'About me'
,
title
:
'About me'
,
...
...
lms/static/js/views/fields.js
View file @
6502eaf7
...
@@ -318,7 +318,7 @@
...
@@ -318,7 +318,7 @@
title
:
this
.
options
.
title
,
title
:
this
.
options
.
title
,
screenReaderTitle
:
this
.
options
.
screenReaderTitle
||
this
.
options
.
title
,
screenReaderTitle
:
this
.
options
.
screenReaderTitle
||
this
.
options
.
title
,
iconName
:
this
.
options
.
iconName
,
iconName
:
this
.
options
.
iconName
,
required
:
this
.
options
.
required
,
showBlankOption
:
(
!
this
.
options
.
required
||
!
this
.
modelValueIsSet
())
,
selectOptions
:
this
.
options
.
options
,
selectOptions
:
this
.
options
.
options
,
message
:
this
.
helpMessage
message
:
this
.
helpMessage
}));
}));
...
@@ -385,10 +385,12 @@
...
@@ -385,10 +385,12 @@
},
},
saveSucceeded
:
function
()
{
saveSucceeded
:
function
()
{
this
.
_super
();
if
(
this
.
editable
===
'toggle'
)
{
if
(
this
.
editable
===
'toggle'
)
{
this
.
showDisplayMode
(
true
);
this
.
showDisplayMode
(
true
);
}
else
{
this
.
showEditMode
(
true
);
}
}
this
.
_super
();
},
},
disableField
:
function
(
disable
)
{
disableField
:
function
(
disable
)
{
...
...
lms/templates/fields/field_dropdown.underscore
View file @
6502eaf7
...
@@ -10,8 +10,8 @@
...
@@ -10,8 +10,8 @@
<span class="u-field-value">
<span class="u-field-value">
<% if (mode === 'edit') { %>
<% if (mode === 'edit') { %>
<select name="select" id="u-field-select-<%- id %>" aria-describedby="u-field-
help-
message-<%- id %>">
<select name="select" id="u-field-select-<%- id %>" aria-describedby="u-field-message-<%- id %>">
<% if (
!required
) { %>
<% if (
showBlankOption
) { %>
<option value=""></option>
<option value=""></option>
<% } %>
<% } %>
<% _.each(selectOptions, function(selectOption) { %>
<% _.each(selectOptions, function(selectOption) { %>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment