=== modified file 'dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/form.js' --- dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/form.js 2012-11-15 11:17:51 +0000 +++ dhis-2/dhis-web/dhis-web-dataentry/src/main/webapp/dhis-web-dataentry/javascript/form.js 2012-11-15 13:17:17 +0000 @@ -70,6 +70,14 @@ var EVENT_FORM_LOADED = "dhis-web-dataentry-form-loaded"; +(function( $ ) { + $.safeEach = function( arr, fn ) { + if( arr ) { + $.each( arr, fn ); + } + }; +})( jQuery ); + /** * Page init. The order of events is: * @@ -727,7 +735,7 @@ var dataSetList = []; - $.each(orgUnitDataSets, function(idx, item) { + $.safeEach(orgUnitDataSets, function(idx, item) { var dataSetId = orgUnitDataSets[idx]; var dataSetName = dataSets[dataSetId].name; @@ -749,17 +757,17 @@ { var dataSetList = []; - $.each(orgUnits, function(idx, item) { + $.safeEach(orgUnits, function(idx, item) { dataSetList.push.apply( dataSetList, getSortedDataSetList(item) ) }); var filteredDataSetList = []; - $.each(dataSetList, function(idx, item) { + $.safeEach(dataSetList, function(idx, item) { var formType = dataSets[item.id].type; var found = false; - $.each(filteredDataSetList, function(i, el) { + $.safeEach(filteredDataSetList, function(i, el) { if(item.name == el.name) found = true; @@ -799,7 +807,7 @@ var dataSetValid = false; - $.each(dataSetList, function(idx, item) { + $.safeEach(dataSetList, function(idx, item) { addOptionById( 'selectedDataSetId', item.id, item.name ); if ( dataSetId == item.id ) @@ -816,7 +824,7 @@ { $('#selectedDataSetId').append(''); - $.each(childrenDataSets, function(idx, item) { + $.safeEach(childrenDataSets, function(idx, item) { $('