How to apply logic to only the current form in HFE VIEW mode

Hi guys,

I have noticed that when I write some jQuery in an HFE (HTML Form Entry) form, when the form is loaded, I will have access to the whole page DOM. It won’t limit to the current form.

In VIEW mode, because we may want to display many forms in the same time (example with the Patient Dashboard Why are patient dashboard concepts displayed in random order?) without necessarily run the logic for them all, it is necessary to find only the current <htmlform> markup

The way I do now is:

jQuery(document).ready(function(){
	jQuery("htmlform").each(function (index, currentForm) {
		if (jQuery(currentForm).attr("formUuid") == "3faa978f-8c89-4f8e-b29f-17fd11099ecf") {
		// do whatever
		}
	});
});

Where “3faa978f-8c89-4f8e-b29f-17fd11099ecf” is the UUID of my current form.

Q: Is there a better way to find the <htmlform> tag of the form that actually contains that script (without having to hardcode the form UUID) ? Or is there a way to limit the scope of jQuery ?

Thank you

Hmm, I hadn’t thought of this.

One possible under-the-hood solution to this could be to change the code in the HFE module so that in FormEntryContext when you register a widget, if it’s in VIEW mode it prefixes the widget’s DOM id with the encounter id. (This would probably break some VIEW mode tests in the HFE module.)

@mogoodrich, you might want to check whether this leads to a bug in the Mirebalais code where if you have >1 vitals form open on the Visit dashboard, then the BMI javascript conflicts…

Interesting point. It does seem like we should fix this, I will try to explore further.

Looks like we did deal with this and take care of it previously, albeit rather hackily. Looks like each form calculates all the BMIs:

 // handle displaying the bmi when in VIEW mode
            jq(function() {

                // we have to iterate through in case there are multiple vitals forms
                // displayed on a single page

                jq('htmlform').each(function(index, form) {
                    jq(form).find('#calculated-bmi-continue').hide();
                    jq(form).find('#no-calculated-bmi').hide();

                    var wt = jq(form).find('#weight_kg').find('.value').text();
                    var ht = jq(form).find('#height_cm').find('.value').text();

                    var bmi = calculateBmi(wt, ht);

                    if (bmi != null &amp;&amp; !isNaN(bmi)) {
                        jq(form).find('#calculated-bmi-wrapper').show();
                        jq(form).find('#calculated-bmi').html(bmi.toFixed(1));
                        jq(form).find('#hidden-calculated-bmi').val(bmi.toFixed(1));
                    }
                });

            });