Permalink
Browse files

MDL-27728 Moodleforms: Added validation for element before checking e…

…lement values
  • Loading branch information...
1 parent 3a5778e commit 63ff3268355aa00e3e0a132fe1df9f18724b5062 Rajesh Taneja committed Aug 2, 2011
Showing with 19 additions and 4 deletions.
  1. +19 −4 lib/formslib.php
View
@@ -1729,6 +1729,12 @@ function getValidationScript()
function qf_errorHandler(element, _qfMsg) {
div = element.parentNode;
+
+ if ((div == undefined) || (element.name == undefined)) {
+ //no checking can be done for undefined elements so let server handle it.
+ return true;
+ }
+
if (_qfMsg != \'\') {
var errorSpan = document.getElementById(\'id_error_\'+element.name);
if (!errorSpan) {
@@ -1778,16 +1784,25 @@ function qf_errorHandler(element, _qfMsg) {
$elementName);
$js .= '
function validate_' . $this->_formName . '_' . $escapedElementName . '(element) {
+ if (undefined == element) {
+ //required element was not found, then let form be submitted without client side validation
+ return true;
+ }
var value = \'\';
var errFlag = new Array();
var _qfGroups = {};
var _qfMsg = \'\';
var frm = element.parentNode;
- while (frm && frm.nodeName.toUpperCase() != "FORM") {
- frm = frm.parentNode;
+ if ((undefined != element.name) && (frm != undefined)) {
+ while (frm && frm.nodeName.toUpperCase() != "FORM") {
+ frm = frm.parentNode;
+ }
+ ' . join("\n", $jsArr) . '
+ return qf_errorHandler(element, _qfMsg);
+ } else {
+ //element name should be defined else error msg will not be displayed.
+ return true;
}
-' . join("\n", $jsArr) . '
- return qf_errorHandler(element, _qfMsg);
}
';
$validateJS .= '

0 comments on commit 63ff326

Please sign in to comment.