Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Grading types should not allow empty field for "Total Number" and "Numbe... #2026

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,10 @@ define ["js/models/settings/course_grader"], (CourseGrader) ->
expect(model.get('weight')).toBe(7)
expect(model.get('min_count')).toBe(3)
expect(model.get('drop_count')).toBe(1)

it "gives validation error if min_count is less than 1 or drop_count is NaN", ->
model = new CourseGrader()
errors = model.validate({min_count: 0, drop_count: ''}, {validate:true})
expect(errors.min_count).toBe('Please enter an integer greater than 0.')
expect(errors.drop_count).toBe('Please enter an integer.')

12 changes: 7 additions & 5 deletions cms/static/js/models/settings/course_grader.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,18 @@ var CourseGrader = Backbone.Model.extend({
}
}}
if (_.has(attrs, 'min_count')) {
if (!isFinite(attrs.min_count) || /\D+/.test(attrs.min_count)) {
errors.min_count = gettext("Please enter an integer.");
var intMinCount = parseInt(attrs.min_count, 10);
if (!isFinite(intMinCount) || /\D+/.test(intMinCount) || intMinCount < 1) {
errors.min_count = gettext("Please enter an integer greater than 0.");
}
else attrs.min_count = parseInt(attrs.min_count, 10);
else attrs.min_count = intMinCount;
}
if (_.has(attrs, 'drop_count')) {
if (!isFinite(attrs.drop_count) || /\D+/.test(attrs.drop_count)) {
var intDropCount = parseInt(attrs.drop_count, 10);
if (!isFinite(intDropCount) || /\D+/.test(intDropCount) || isNaN(intDropCount)) {
errors.drop_count = gettext("Please enter an integer.");
}
else attrs.drop_count = parseInt(attrs.drop_count, 10);
else attrs.drop_count = intDropCount;
}
if (_.has(attrs, 'min_count') && _.has(attrs, 'drop_count') && attrs.drop_count > attrs.min_count) {
errors.drop_count = _.template(
Expand Down