Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-ora2
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-ora2
Commits
dd57c8b5
Commit
dd57c8b5
authored
Nov 24, 2014
by
muzaffaryousaf
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
More accurate validation for date & time in studio editor.
TNL-58
parent
51df3aa6
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
29 additions
and
5 deletions
+29
-5
openassessment/xblock/static/js/openassessment-studio.min.js
+0
-0
openassessment/xblock/static/js/spec/studio/oa_edit_fields.js
+6
-0
openassessment/xblock/static/js/src/studio/oa_edit_fields.js
+23
-5
No files found.
openassessment/xblock/static/js/openassessment-studio.min.js
View file @
dd57c8b5
This diff is collapsed.
Click to expand it.
openassessment/xblock/static/js/spec/studio/oa_edit_fields.js
View file @
dd57c8b5
...
...
@@ -44,6 +44,10 @@ describe("OpenAssessment.DatetimeControl", function() {
testValidateDate
(
datetimeControl
,
"99999999-01-01"
,
"00:00"
,
false
,
expectedError
);
testValidateDate
(
datetimeControl
,
"2014-99999-01"
,
"00:00"
,
false
,
expectedError
);
testValidateDate
(
datetimeControl
,
"2014-01-99999"
,
"00:00"
,
false
,
expectedError
);
//invalid month
testValidateDate
(
datetimeControl
,
"2014-13-01"
,
"00:00"
,
false
,
expectedError
);
//invalid day
testValidateDate
(
datetimeControl
,
"2014-02-30"
,
"00:00"
,
false
,
expectedError
);
});
it
(
"validates invalid times"
,
function
()
{
...
...
@@ -64,6 +68,8 @@ describe("OpenAssessment.DatetimeControl", function() {
testValidateDate
(
datetimeControl
,
"2001-12-31"
,
"00:00"
,
true
);
testValidateDate
(
datetimeControl
,
"2014-04-01"
,
"12:34"
,
true
);
testValidateDate
(
datetimeControl
,
"2014-04-01"
,
"23:59"
,
true
);
// single character for month and date.
testValidateDate
(
datetimeControl
,
"2014-4-1"
,
"23:59"
,
true
);
});
it
(
"clears validation errors"
,
function
()
{
...
...
openassessment/xblock/static/js/src/studio/oa_edit_fields.js
View file @
dd57c8b5
...
...
@@ -227,16 +227,34 @@ OpenAssessment.DatetimeControl.prototype = {
**/
validate
:
function
()
{
var
datetimeString
=
this
.
datetime
();
var
matches
=
datetimeString
.
match
(
/^
\d{4}
-
\d{2}
-
\d{2}
T
\d{2}
:
\d{2}
$/g
);
var
isValid
=
(
matches
!==
null
);
var
dateString
=
$
(
this
.
datePicker
,
this
.
element
).
val
();
var
timeString
=
$
(
this
.
timePicker
,
this
.
element
).
val
();
if
(
!
isValid
)
{
//date validation
var
isDateValid
=
false
;
//try: to catch the error thrown by parseDate if date is not in expected format.
try
{
var
parsedDate
=
$
.
datepicker
.
parseDate
(
"yy-mm-dd"
,
dateString
);
if
(
parsedDate
instanceof
Date
)
{
isDateValid
=
true
;
}
}
catch
(
err
)
{
// do nothing.
}
if
(
!
isDateValid
)
{
$
(
this
.
datePicker
,
this
.
element
).
addClass
(
"openassessment_highlighted_field"
);
}
//time validation
var
matches
=
timeString
.
match
(
/^
\d{2}
:
\d{2}
$/g
);
var
isTimeValid
=
(
matches
!==
null
);
if
(
!
isTimeValid
)
{
$
(
this
.
timePicker
,
this
.
element
).
addClass
(
"openassessment_highlighted_field"
);
}
return
isValid
;
return
(
isDateValid
&&
isTimeValid
)
;
},
/**
...
...
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