← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 12584: if optionset is rendered as radio button in caseentry, select correct button on loading of form w...

 

------------------------------------------------------------
revno: 12584
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2013-10-11 12:29:07 +0200
message:
  if optionset is rendered as radio button in caseentry, select correct button on loading of form with values
modified:
  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


--
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-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	2013-10-11 09:28:07 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/defaultDataEntryForm.vm	2013-10-11 10:29:07 +0000
@@ -74,10 +74,10 @@
 					<table style='width:100%'>
 						<tr>
 							<td>
-					<input id='$id' name="$id" options='no' type='radio' optionset='$programStageDataElement.dataElement.optionSet.uid'
+					<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()' }"
 						#if( $patientDataValue.value == $option) checked #end
-						onclick="saveRadio( '$programStageDataElement.dataElement.uid', '$option' )" tabindex="$tabIndex" />$i18n.getString("non_value")
+						onclick="saveRadio( '$programStageDataElement.dataElement.uid', '' )" tabindex="$tabIndex" />$i18n.getString("non_value")
 						</td>
 					#set($index=1)
 					#foreach($option in $programStageDataElement.dataElement.optionSet.options)
@@ -86,7 +86,7 @@
 							#set($index=0)
 						#end
 						<td>
-						<input id='$id' name="$id" type='radio' options='no' optionset='$programStageDataElement.dataElement.optionSet.uid'
+						<input id='$id' class='$id' name="$id" type='radio' options='no' optionset='$programStageDataElement.dataElement.optionSet.uid'
 							data="{compulsory: $programStageDataElement.compulsory, deName:'$programStageDataElement.dataElement.name', deType:'$programStageDataElement.dataElement.getDetailedNumberType()' }" 
 						#if( $patientDataValue.value == $option) checked #end value="$encoder.htmlEncode($option)"
 						onclick="saveRadio( '$programStageDataElement.dataElement.uid', '$option' )" tabindex="$tabIndex" />$encoder.htmlEncode($option)

=== 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	2013-10-11 09:28:07 +0000
+++ dhis-2/dhis-web/dhis-web-caseentry/src/main/webapp/dhis-web-caseentry/javascript/entry.js	2013-10-11 10:29:07 +0000
@@ -755,11 +755,20 @@
 
 function checkAndSetRadio( $field, value ) {
     if( $field.attr('type') === 'radio' ) {
-        if( $.trim(value) === $.trim($field.val()) ) {
-            $field.attr('checked', true);
-            $field[0].checked = true;
-        }
+        var $fields = $("." + $field.attr('id'));
+
+        $.each($fields, function() {
+            var $f = $(this);
+
+            if( $.trim(value) === $.trim($f.val()) ) {
+                $f.attr("checked", true);
+            }
+        });
+
+        return true;
     }
+
+    return false;
 }
 
 function loadProgramStageInstance( programStageInstanceId, always ) {
@@ -775,9 +784,12 @@
                         var field = $('#' + fieldId);
 
                         if ( field ) {
-                            checkAndSetCheckbox(field, obj.values[key].value);
-                            checkAndSetRadio(field, obj.values[key].value);
-                            field.val( decodeURI( obj.values[key].value ) );
+                            var value = obj.values[key].value;
+
+                            if( !checkAndSetRadio(field, value) ) {
+                                field.val(decodeURI(value));
+                                checkAndSetCheckbox(field, value);
+                            }
                         }
                     });
                 }
@@ -872,9 +884,12 @@
             var field = $('#' + fieldId);
 
             if ( field ) {
-                checkAndSetCheckbox(field, value.value);
-                checkAndSetRadio(field, value.value);
-                field.val( decodeURI( value.value ));
+                var value = value.value;
+
+                if( !checkAndSetRadio(field, value) ) {
+                    field.val(decodeURI(value));
+                    checkAndSetCheckbox(field, value);
+                }
             }
         } );