Index: lams_tool_assessment/web/pages/learning/learning.jsp =================================================================== diff -u -r38b6d49113930570f68778048950c2df1875a6be -r1668e000b0959071785e5cdd21732af39bd1505f --- lams_tool_assessment/web/pages/learning/learning.jsp (.../learning.jsp) (revision 38b6d49113930570f68778048950c2df1875a6be) +++ lams_tool_assessment/web/pages/learning/learning.jsp (.../learning.jsp) (revision 1668e000b0959071785e5cdd21732af39bd1505f) @@ -34,6 +34,7 @@ + @@ -98,7 +99,7 @@ //autosave feature - + var autosaveInterval = "30000"; // 30 seconds interval window.setInterval( function(){ @@ -128,9 +129,9 @@ ); - //check if we came back due to missing required question's answer + //check if we came back due to failed answers' validation (missing required question's answer or min words limit not reached) $(document).ready(function(){ - if (${isRequiredAnswerMissed == true}) { + if (${isAnswersValidationFailed == true}) { validateAnswers(); } }); @@ -230,11 +231,13 @@ function validateAnswers() { - if (${finishedLock || !hasEditRight}) { + if (${isEditingDisabled}) { return true; } var missingRequiredQuestions = []; + var minWordsLimitNotReachedQuestions = []; + var maxWordsLimitExceededQuestions = []; @@ -289,28 +292,83 @@ + + //essay question which has max words limit + + var wordCount${status.index} = $('#word-count${status.index}').text(); + //max words limit is exceeded + if(wordCount${status.index} > ${question.maxWordsLimit}) { + maxWordsLimitExceededQuestions.push("${status.index}"); + } + + + //essay question which has min words limit + + var wordCount${status.index} = $('#word-count${status.index}').text(); + //min words limit is not reached + if(wordCount${status.index} < ${question.minWordsLimit}) { + minWordsLimitNotReachedQuestions.push("${status.index}"); + } + //return true in case all required questions were answered, false otherwise - if (missingRequiredQuestions.length == 0) { + if (missingRequiredQuestions.length == 0 && minWordsLimitNotReachedQuestions.length == 0 + && maxWordsLimitExceededQuestions.length == 0) { return true; } else { //remove .warning-answer-required from all questions $('[id^=question-area-]').removeClass('warning-answer-required'); + $('#warning-answers-required').hide(); + $('#warning-min-words-limit').hide(); + $('#warning-max-words-limit').hide(); - //add .warning-answer-required class to those needs to be filled - for (i = 0; i < missingRequiredQuestions.length; i++) { - $("#question-area-" + missingRequiredQuestions[i]).addClass('warning-answer-required'); + if (missingRequiredQuestions.length != 0) { + //add .warning-answer-required class to those needs to be filled + for (i = 0; i < missingRequiredQuestions.length; i++) { + $("#question-area-" + missingRequiredQuestions[i]).addClass('warning-answer-required'); + } + //show alert message as well + $("#warning-answers-required").show(); + } - //show alert message as well - $("#warning-answers-required").show(); + if (maxWordsLimitExceededQuestions.length != 0) { + //add .warning-answer-required class to those needs to be filled + for (i = 0; i < maxWordsLimitExceededQuestions.length; i++) { + $("#question-area-" + maxWordsLimitExceededQuestions[i]).addClass('warning-answer-required'); + } + //show alert message as well + $("#warning-max-words-limit").show(); + } + + if (minWordsLimitNotReachedQuestions.length != 0) { + //add .warning-answer-required class to those needs to be filled + for (i = 0; i < minWordsLimitNotReachedQuestions.length; i++) { + $("#question-area-" + minWordsLimitNotReachedQuestions[i]).addClass('warning-answer-required'); + } + //show alert message as well + $("#warning-min-words-limit").show(); + } + $("html, body").animate({ scrollTop: 0 }, "slow");//window.scrollTo(0, 0); + return false; } } - + + function getNumberOfWords(value, isRemoveHtmlTags) { + + //HTML tags stripping + if (isRemoveHtmlTags) { + value = value.replace(/ /g, '').replace(/<\/?[a-z][^>]*>/gi, ''); + } + value = value.trim(); + + var wordCount = value ? (value.replace(/['";:,.?\-!]+/g, '').match(/\S+/g) || []).length : 0; + return wordCount; + } @@ -350,10 +408,18 @@

-
+
+
+ +
+ +
+ +
+