From 283f877719fdb6504d648d5bec8221ca73eb5ef4 Mon Sep 17 00:00:00 2001 From: Andrew Robert Nicols Date: Wed, 9 Jan 2013 22:47:19 +0000 Subject: [PATCH] MDL-37397 Test for a valid select in formautosubmit Ideally we shouldn't get into this situation, but in cases where the generated select element is incorrectly configured, we should try and handle it gracefully with a warning. --- lib/yui/formautosubmit/formautosubmit.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/yui/formautosubmit/formautosubmit.js b/lib/yui/formautosubmit/formautosubmit.js index 01d666879c8..39525dbf9d1 100644 --- a/lib/yui/formautosubmit/formautosubmit.js +++ b/lib/yui/formautosubmit/formautosubmit.js @@ -40,9 +40,17 @@ YUI.add('moodle-core-formautosubmit', } // Assign this select items 'nothing' value and lastindex (current value) - var thisselect = Y.one('select#' + this.get('selectid')); - thisselect.setData('nothing', this.get('nothing')); - thisselect.setData('startindex', thisselect.get('selectedIndex')); + if (this.get('selectid')) { + var thisselect = Y.one('select#' + this.get('selectid')); + if (thisselect) { + if (this.get('nothing')) { + thisselect.setData('nothing', this.get('nothing')); + } + thisselect.setData('startindex', thisselect.get('selectedIndex')); + } else { + Y.log("Warning: A single_select element was renderered, but the output is not displayed on the page."); + } + } }, /**