Commit e24ddaa3 by zubair-arbi

Merge pull request #2026 from zubair-arbi/zub/bugfix/std988-gradingtypes

Grading types should not allow empty field for "Total Number" and "Numbe...
parents 23dc10d0 4cb03f43
......@@ -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.')
......@@ -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(
......
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