Fixes for course updates date validation.
If the first date the user selects is invalid it is not set on the model. This is because jQuery datepicker's getDate returns the current date when an invalid value is put in the field and the model's initial value is also the current date. So always update the date.
This commit is contained in:
@@ -98,15 +98,9 @@ define ["js/views/course_info_handout", "js/views/course_info_update", "js/model
|
||||
@courseInfoEdit.onNew(@event)
|
||||
expect(@courseInfoEdit.$el.find('.save-button').hasClass("is-disabled")).toEqual(false)
|
||||
@courseInfoEdit.$el.find('input.date').val(value).trigger("change")
|
||||
courseInfoEdit = @courseInfoEdit
|
||||
jasmine.waitUntil(->
|
||||
courseInfoEdit.$el.find('.save-button').hasClass('is-disabled') == true
|
||||
).then ->
|
||||
courseInfoEdit.$el.find('input.date').val('01/01/16').trigger 'change'
|
||||
jasmine.waitUntil(->
|
||||
courseInfoEdit.$el.find('.save-button').hasClass('is-disabled') == false
|
||||
).always done
|
||||
return
|
||||
expect(@courseInfoEdit.$el.find('.save-button').hasClass("is-disabled")).toEqual(true)
|
||||
@courseInfoEdit.$el.find('input.date').val("01/01/16").trigger("change")
|
||||
expect(@courseInfoEdit.$el.find('.save-button').hasClass("is-disabled")).toEqual(false)
|
||||
|
||||
cancelEditingUpdate = (update, modalCover, useCancelButton) ->
|
||||
if useCancelButton
|
||||
|
||||
@@ -15,21 +15,13 @@ function($, date, TriggerChangeEventOnEnter) {
|
||||
var timefield = $(div).find("input.time");
|
||||
var cacheview = view;
|
||||
var setfield = function (event) {
|
||||
var newVal = getDate(datefield, timefield),
|
||||
oldTime = new Date(cacheModel.get(fieldName)).getTime();
|
||||
if (newVal) {
|
||||
if (!cacheModel.has(fieldName) || oldTime !== newVal.getTime()) {
|
||||
cacheview.clearValidationErrors();
|
||||
cacheview.setAndValidate(fieldName, newVal, event);
|
||||
}
|
||||
}
|
||||
else {
|
||||
// Clear date (note that this clears the time as well, as date and time are linked).
|
||||
// Note also that the validation logic prevents us from clearing the start date
|
||||
// (start date is required by the back end).
|
||||
cacheview.clearValidationErrors();
|
||||
cacheview.setAndValidate(fieldName, null, event);
|
||||
}
|
||||
var newVal = getDate(datefield, timefield);
|
||||
|
||||
// Setting to null clears the time as well, as date and time are linked.
|
||||
// Note also that the validation logic prevents us from clearing the start date
|
||||
// (start date is required by the back end).
|
||||
cacheview.clearValidationErrors();
|
||||
cacheview.setAndValidate(fieldName, (newVal || null), event);
|
||||
};
|
||||
|
||||
// instrument as date and time pickers
|
||||
|
||||
@@ -71,7 +71,7 @@ define(["js/views/validation", "codemirror", "js/models/course_update",
|
||||
},
|
||||
|
||||
handleValidationError : function(model, error) {
|
||||
var ele = this.$el.find('#course-update-list li[name=\"'+model.cid+'\"');
|
||||
var ele = this.$el.find('#course-update-list li[name=\"'+model.cid+'\"]');
|
||||
$(ele).find('.message-error').remove();
|
||||
for (var field in error) {
|
||||
if (error.hasOwnProperty(field)) {
|
||||
@@ -86,7 +86,7 @@ define(["js/views/validation", "codemirror", "js/models/course_update",
|
||||
|
||||
validateModel: function(model) {
|
||||
if (model.isValid()) {
|
||||
var ele = this.$el.find('#course-update-list li[name=\"' + model.cid + '\"');
|
||||
var ele = this.$el.find('#course-update-list li[name=\"' + model.cid + '\"]');
|
||||
$(ele).find('.message-error').remove();
|
||||
$(ele).find('.save-button').removeClass('is-disabled');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user