Problems with setValue() jQuery method in HTML Form Entry

Hi everyone,

I would like to set the value of an obs from my Javascript. That observation is of <obs … style=“autocomplete”> style.

To do so, I use the method provided by HtmlFormEntry module: setValue()

Here is the script at the top of my HTML form:

jQuery("#select-order").click(function() {
    	setValue('drug-dispensed.value', "PENICILLIN V");
});

and the obs html code:

<obs id="drug-dispensed" conceptId="1282" answerClasses="Drug" style="autocomplete"/>

Upon click on the “select-order” item, the value “PENICILLIN V” fills in the auto-complete obs correctly.

However, the obs is not saved when hitting the Save button.

The user needs to click in the field, edit the text (like type or remove a letter) and pick from the auto-complete list to really validate the obs value.

After that, the obs will be saved correctly when clicking on the Save button

Note that this behavior doesn’t seem to match with the documentation:

Note that if setValue() method is used with an Autocomplete widget, the display value will not be updated, as the setValue method only updates the hidden value of Autocomplete widget. However once the form is saved and submitted, it will save the values correctly.

Seems like a bug/improvement… feel free to enter a ticket in the Html Form Entry project if it doesn’t exist.

Per the behavior not matching the documentation, try setting the value to the actual submitted value–the concept ID, not the text value, ie:

jQuery("#select-order").click(function() {
    	setValue('drug-dispensed.value', 323);
});

… and see if this would do what you want. If it does, but you don’t want to reference a concept by ID (since this is generally bad practice since IDs vary from DB to DB) you can do something ugly but workable like this:

var conceptId = "<lookup expression="fn.getConcept('concept-uuid-or-mapping')"/>"  // hopefully I got the nested quotes right

jQuery("#select-order").click(function() {
    	setValue('drug-dispensed.value', conceptId);
});
1 Like

Thanks @mogoodrich I’ve tried to set it to its ID but it doesn’t work either.

I think the problem is not what is actually entered, it is more that the auto-complete field doesn’t seem to realize that it has been filled. Is there a change() method or something like this that I should call to “force” the field to update (similar as a user input) ?

I will enter a ticket.

1 Like

A post was split to a new topic: Sample drug order form for HTML Form Entry?

Could you please share your medicine order HTML Form? Also the screenshot to quickly understand the behaviour and look of form.