← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 17142: Mandatory DE validation doesn't work in case entry form.

 

------------------------------------------------------------
revno: 17142
committer: Tran Chau<tran.hispvietnam@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2014-10-17 10:31:13 +0700
message:
  Mandatory DE validation doesn't work in case entry form.
modified:
  dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/program/DefaultProgramDataEntryService.java
  dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/defaultDataEntryForm.vm
  dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/entry.js
  dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/sectionDataEntryForm.vm
  dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/singleDataEntryForm.vm


--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk

Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/program/DefaultProgramDataEntryService.java'
--- dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/program/DefaultProgramDataEntryService.java	2014-10-16 06:17:19 +0000
+++ dhis-2/dhis-services/dhis-service-tracker/src/main/java/org/hisp/dhis/program/DefaultProgramDataEntryService.java	2014-10-17 03:31:13 +0000
@@ -573,7 +573,7 @@
         String inputHTML = "";
         if ( dataElement != null )
         {
-            String metaData = "<input id=\'" + id + "\' name=\'" + id + "\' options=\'no\' type=\'radio\' optionset='"
+            String metaData = "<input class='optionset' id=\'" + id + "\' name=\'" + id + "\' options=\'no\' type=\'radio\' optionset='"
                 + dataElement.getOptionSet().getUid() + "'";
             metaData += " data=\"{compulsory:$COMPULSORY, deName:\'$DATAELEMENTNAME\', deType:\'"
                 + dataElement.getDetailedNumberType() + "\' }\" ";
@@ -588,7 +588,7 @@
                 inputHTML += " checked ";
             }
 
-            inputHTML += "onclick=\"saveRadio( \'" + dataElement.getUid() + "\', \'$option\' )\" />"
+            inputHTML += " value='' onclick=\"saveRadio( \'" + dataElement.getUid() + "\', \'$option\' )\" />"
                 + i18n.getString( "non_value" );
             inputHTML += " </td>";
 

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/defaultDataEntryForm.vm'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/defaultDataEntryForm.vm	2014-08-05 05:57:06 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/defaultDataEntryForm.vm	2014-10-17 03:31:13 +0000
@@ -74,9 +74,10 @@
 					<table style='width:100%'>
 						<tr>
 							<td>
-							<input id='$id' class='$id' name="$id" type='radio' options='no' optionset='$programStageDataElement.dataElement.optionSet.uid'
+							<input id='$id' class='$id optionset' name="$id" type='radio' options='no' optionset='$programStageDataElement.dataElement.optionSet.uid'
 								data="{compulsory: $programStageDataElement.compulsory, deName:'$programStageDataElement.dataElement.name', deType:'$programStageDataElement.dataElement.getDetailedNumberType()' }"
 								#if( $dataValue.value == "$option.name") checked #end
+								value=''
 								onclick="saveRadio( '$programStageDataElement.dataElement.uid', '' )" tabindex="$tabIndex" />$i18n.getString("non_value")
 						</td>
 					#set($index=1)

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/entry.js'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/entry.js	2014-08-05 05:57:06 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/entry.js	2014-10-17 03:31:13 +0000
@@ -544,7 +544,8 @@
 function runCompleteEvent( isCreateEvent ) {
     var flag = false;
 
-    $("#dataEntryFormDiv input[name='entryfield'],select[name='entryselect']").each(function() {
+    $("#dataEntryFormDiv .optionset").parent().removeClass("errorCell");
+    $("#dataEntryFormDiv input[name='entryfield'],select[name='entryselect'],.optionset:checked").each(function() {
         $(this).parent().removeClass("errorCell");
 
         var arrData = $(this).attr('data').replace('{', '').replace('}', '').replace(/'/g, "").split(',');
@@ -956,31 +957,60 @@
 
 function runValidation()
 {
-	$('#loading-bar').show();
-	$('#loading-bar').dialog({
-		modal:true,
-		width: 330
-	});
-	$("#loading-bar").siblings(".ui-dialog-titlebar").hide(); 
-	
-	var programStageInstanceId = jQuery('.stage-object-selected').attr('id').split('_')[1];
-	$('#validateProgramDiv' ).load( 'validateProgram.action',
-		{
-			programStageInstanceId: programStageInstanceId
-		},
-		function(){
-			$( "#loading-bar" ).dialog( "close" );
-			
-			$('#validateProgramDiv' ).dialog({
-				title: i18n_violate_validation,
-				maximize: true, 
-				closable: true,
-				modal:true,
-				overlay:{background:'#000000', opacity:0.1},
-				width: 800,
-				height: 450
+	$("#dataEntryFormDiv .optionset").parent().removeClass("errorCell");
+	var flag = false;
+	$("#dataEntryFormDiv input[name='entryfield'],select[name='entryselect'],.optionset:checked").each(function() {
+        $(this).parent().removeClass("errorCell");
+  
+        var arrData = $(this).attr('data').replace('{', '').replace('}', '').replace(/'/g, "").split(',');
+        var data = [];
+  
+        $.each(arrData, function() {
+            var values = this.split(':');
+            values = $.trimArray(values);
+            data[values[0]] = values[1];
+        });
+  
+        var compulsory = data['compulsory'];
+  
+        if( compulsory == 'true' && ( !$(this).val() || $(this).val() == "undefined" ) ) {
+            flag = true;
+            $(this).parent().addClass("errorCell");
+        }
+    });
+ 
+	if( flag ) {
+         alert(i18n_error_required_field);
+         return;
+    }
+    else
+    {
+		$('#loading-bar').show();
+		$('#loading-bar').dialog({
+			modal:true,
+			width: 330
+		});
+		$("#loading-bar").siblings(".ui-dialog-titlebar").hide(); 
+		
+		var programStageInstanceId = jQuery('.stage-object-selected').attr('id').split('_')[1];
+		$('#validateProgramDiv' ).load( 'validateProgram.action',
+			{
+				programStageInstanceId: programStageInstanceId
+			},
+			function(){
+				$( "#loading-bar" ).dialog( "close" );
+				
+				$('#validateProgramDiv' ).dialog({
+					title: i18n_violate_validation,
+					maximize: true, 
+					closable: true,
+					modal:true,
+					overlay:{background:'#000000', opacity:0.1},
+					width: 800,
+					height: 450
+				});
 			});
-		});
+	}
 }
 
 function searchOptionSet( uid, query, success ) {

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/sectionDataEntryForm.vm'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/sectionDataEntryForm.vm	2014-08-05 05:57:06 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/sectionDataEntryForm.vm	2014-10-17 03:31:13 +0000
@@ -86,8 +86,8 @@
 										<table style='width:100%'>
 											<tr>
 												<td>
-													<input id='$id' name="$id" type='radio' options='no' optionset="$programStageDataElement.dataElement.optionSet.uid"
-														data="{compulsory: $programStageDataElement.compulsory, deName:'$programStageDataElement.dataElement.name', deType:'$programStageDataElement.dataElement.getDetailedNumberType()' }" 
+													<input class='optionset' id='$id' name="$id" type='radio' options='no' optionset="$programStageDataElement.dataElement.optionSet.uid"
+														data="{compulsory: $programStageDataElement.compulsory, deName:'$programStageDataElement.dataElement.name', deType:'$programStageDataElement.dataElement.getDetailedNumberType()' }" value='' 
 														#if( $dataValue.value == "$option.name") checked #end
 														onclick="saveRadio( '$programStageDataElement.dataElement.uid', '$option.code' )" tabindex="$tabIndex" />$i18n.getString("non_value")
 											</td>

=== modified file 'dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/singleDataEntryForm.vm'
--- dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/singleDataEntryForm.vm	2014-08-04 15:58:47 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/singleDataEntryForm.vm	2014-10-17 03:31:13 +0000
@@ -125,8 +125,8 @@
 													<table style='width:100%'>
 														<tr>
 															<td>
-													<input id='$id' class='$id' name="$id" options='no' type='radio' optionset='$programStageDataElement.dataElement.optionSet.uid'
-														data="{compulsory: $programStageDataElement.compulsory, deName:'$programStageDataElement.dataElement.name', deType:'$programStageDataElement.dataElement.getDetailedNumberType()' }"
+													<input id='$id' class='$id optionset' name="$id" options='no' type='radio' optionset='$programStageDataElement.dataElement.optionSet.uid'
+														data="{compulsory: $programStageDataElement.compulsory, deName:'$programStageDataElement.dataElement.name', deType:'$programStageDataElement.dataElement.getDetailedNumberType()' }" value='' 
 														#if( $dataValue.value == "$option.code") checked #end
 														onclick="saveRadio( '$programStageDataElement.dataElement.uid', '' )" tabindex="$tabIndex" />$i18n.getString("non_value")
 														</td>