Wiki Spaces

Documentation
Projects
Resources

Get Help from Others

Q&A: Ask OpenMRS
Discussion: OpenMRS Talk
Real-Time: IRC Chat | Slack

Documentation

Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: updated examples $j to jQuery (which works with old and new UI)

...

  • argument: idAndProperty the field you want to get (for example "weight.value")
  • returns: a JQuery selector for the field you requested
    Example for obs (since: 1.6.8):

    Code Block
    $jjQuery(function() {
             getField('weight.value').change(function() {
             window.alert('Weight is now ' + getValue('weight.value'))
        });
    });
    

    Example for encounter details (since: 1.9.0):

    Code Block
    $jjQuery(function() {
             getField('encounterDate.value').change(function() {
             window.alert('Encounter date is ' + getValue('encounterDate.value'))
             });
    });
    
    $jjQuery(function() {
             getField('encounterLocation.value').change(function() {
             window.alert('Location is ' + getValue('encounterLocation.value'))
             });
    });
    
    $jjQuery(function() {
             getField('encounterProvider.value').change(function() {
             window.alert('Provider is ' + getValue('encounterProvider.value'))
             });
    });
    

...

  • argument: idAndProperty the field you want to get (for example "weight.value")
  • returns: the value of the specified field
    Example for obs (since: 1.6.8):

    Code Block
    $jjQuery(function() {
         window.alert('You entered ' + getValue('weight.value') + 'kg as the weight');
    });
    

    Example for encounter details (since: 1.9.0):

    Code Block
    $jjQuery(function() {
             window.alert('Encounter date is ' + getValue('encounterDate.value')
               + '.\nEncounter date error is ' + getValue('encounterDate.error')
                 + '.\nEncounter location is ' + getValue('encounterLocation.value')
           + '.\nEncounter location error is ' + getValue('encounterLocation.error')
                           + '.\nProvider is ' + getValue('encounterProvider.value')
                     + '.\nProvider error is ' + getValue('encounterProvider.error'))
    });
    

...

  • argument: idAndProperty the field you want to set the value of (for example "weight.value")
  • value: the value you want to set
    Example for obs (since: 1.6.8):

    Code Block
    $jjQuery(function() {
         setValue('weight.value', 74);
         setValue('scheduledVisit.value', true);
         setValue('howTravelClinic.value', 456); // 456 is a concept id that's a legal answer to this question
    });
    

    Example for encounter details (since: 1.9.0):

    Code Block
    $jjQuery(function() {
         setValue('encounterDate.value', "2012-01-01"); // 2012-01-01 is a valid date
         setValue('encounterDate.error', "*Some Encounter dateError*");
         setValue('encounterLocation.value', 15); // 15 is a location id
         setValue('encounterLocation.error', "*Some Location Error*");
         setValue('encounterProvider.value', 146552); // 146552 is a provider id
         setValue('encounterProvider.error', "*Some Provider Error*");
    });
    

...

Code Block
<script type="text/javascript">
if(jQuery){
 $jjQuery(document).ready(function(){
 	if ( $j.browser.msie ) {
 		$j(":checkbox").click(function(){
			 $j(this).change();
	 });
 }
 $j(".enableDisable").each(function(){
	 var group = $j(this);
	 function disableFn(){
		 group.children("#disabled").fadeTo(250,0.33);
		 group.children("#disabled").find(":checkbox").attr("checked",false); //uncheck
		 group.children("#disabled").find("input[type$='text']").val("");
		 group.children("#disabled").find("input").attr("disabled",true);  //disable
	 }
 function enableFn(){
	 group.children("#disabled").fadeTo(250,1);
	 group.children("#disabled").find("input").attr("disabled",false);
 }
 disableFn();
 $j(this).children("#trigger").find(":checkbox:first").change(function(){
	 var checked = $j(this).attr("checked");
	 if(checked == true){
		  enableFn();
	 }else{
 		 disableFn();
	 }
 });
});


 $j(".checkboxGroup").each(function(){
	 var group = $j(this);
	 var uncheckAll = function(){
		 group.find("input[type$='checkbox']").attr("checked",false);
		 group.find("input[type$='checkbox']").change();
	 }
	 var uncheckRadioAndAll = function(){
	 group.find("#checkboxAll,#checkboxRadio").find("input[type$='checkbox']").attr("checked",false);
	 group.find("#checkboxAll,#checkboxRadio").find("input[type$='checkbox']").change();
 }



 group.find("#checkboxAll").find("input").click(
	 /*  This was tricky... A number of things needed to happen
 		Basically, This is supposed to treat a group of inputs as if
	 	were all one big checkbox. It is designed so that a checkbox
		 can be next to an input, and the user clicks the input, the
	 	checkbox checks as well. But, when the user clicks the checkbox,
		 the browser marks the checkbox as checked. Therefore, when we check
		 if the checkbox is already checked, it always respondes true...
		 We needed to have 2 cases: when the clicking action is on the first checkbox
		 and when the action is on any other.  */
 	function(){
		 var flip;
		 var checked = $j(this).siblings(":checkbox:first").attr("checked");
		 if($j(this).attr("name") == $j(this).parents("#checkboxAll:first").find(":checkbox:first").attr("name")){
			 checked = $j(this).attr("checked");
			 flip = checked;
		 }else{
			 flip = !checked;
		 }
		 if($j(this).attr("type") == "text") if(flip == false) flip = !filp; // this is so the user doesn't go to check the checkbox, then uncheck it when they hit the input.
		 uncheckAll();
		 $j(this).parents("#checkboxAll:first").find(":checkbox").attr("checked",flip);
		 $j(this).parents("#checkboxAll:first").find(":checkbox").change();
	 }
 );



 group.find("#checkboxRadio").find("input[type$='checkbox']").click(function(){
	 uncheckAll();
	 $j(this).siblings("input[type$='checkbox']").attr("checked",false);
	 $j(this).attr("checked",true);
	 $j(this).change();
 });

 group.find("#checkboxCheckbox").click(
	 function(){
		 uncheckRadioAndAll();
	 }
 );
 });
 });
}
</script>

...