Thanks for answering! I almost missed your reply because it was in a digest. I was watching for the subject line.
I often use conditionals to execute code such as resetting counters or prepping a loop but I think this was the first time I had done it inside an AUC. I removed it and tinkered with several combinations of the bindings. I couldn't find an example for closeUpdateContainerID. Is it _required_ with onClose? While using it, it was trying to update the container before the list was rebuilt.
It still doesn't work 100% but it is much closer. Also, the question about the entire page being processed when updating a portion of the page wasn't answered. Any thoughts or insights?
1. The AjaxAutoComplete works correctly the first time but if I open the AMD again, then the styling is gone -- hard to read but it is functional.
2. Tab doesn't work from fields within the AMD. Is this is a know bug/feature/issue with AMD?
3. I have to click outside the Details field (tab doesn't work) before clicking Add. If I just click on Add before leaving the field, then addLabTestData() doesn't seem to get called. The button is enabled when a selection is made in the AAC. I suspect it is a timing issue between the UC updating and list being recreated.
Here is the source for the two components. I've trimmed it down to the relevant pieces so you can see what I am trying to accomplish (it is still about 250 lines).
MPanelOrders.html ( an embedded component which calls the AMD )
<webobject name="ordersForm">
<!-- This UC will get re-loaded when "Add" is clicked in the AMD -->
<webobject name="labTestUC">
<!-- This just prints a timestamp -->
<webobject name="testMarker" /><br/>
<p>The following labs and tests will be automatically ordered:</p>
<br/>
<ul>
<!-- current labs and tests. Will be recreated when "Add" is clicked in AMD -->
<webobject name="labTestList">
<li>
<!-- A custom checkbox and label for each lab and test -->
<span>
<webobject name="labTestCB"/>
<webobject name="labTestLabel"> </webobject>
<webobject name="labTestName" />
<webobject name="labTestCB_OF" />
</span>
</li>
</webobject>
</ul>
<!-- Button to launch the AjaxModalDialog -->
<div>
<webobject name="addLabTestPopup"/> <span>Order additional Labs and Tests</span>
</div>
</webobject name="labTestUC">
</webobject name="ordersForm">
====================================
MPanelOrders.wod
ordersForm: WOForm
{
id = "ordersForm";
multipleSubmit = true;
}
labTestUC: AjaxUpdateContainer
{
elementName = "div";
id = "labTestUC";
}
labTestList: WORepetition
{
list = patientLabTestList;
item = patientLabTestItem;
index = patientLabTestIndex;
}
labTestCB: WOCheckBox
{
id = patientLabTestID;
checked = patientLabTestCB;
}
labTestCB_OF: AjaxObserveField
{
observeFieldID = patientLabTestID;
action = ""> // no-op that gives the server a chance to update
fullSubmit = false;
}
labTestLabel: WOGenericContainer
{
elementName = "label";
for = "">
}
labTestName: WOString { value = patientLabTestDisplayName; }
addLabTestPopup: AjaxModalDialog
{
autoFocusing = false;
centerVertically = true;
locked = true;
transitions = false;
action = "">
>
// closeUpdateContainerID = "labTestUC";
title = "Add Another Lab or Test";
label = "Add another Lab or Test";
class = "addLab";
closeValue = "x";
width = 500;
height = 300;
}
testMarker: WOString
{
value = testMarker; // Current timestamp
dateformatter = "%m/%d/%Y %H:%M:%S";
}
=========================
MPanelOrders.java
public WOActionResults addLabTestPopup()
{
AddLabTestPopup popup = pageWithName( AddLabTestPopup.class );
// Create a new _patientLabTest object. It needs info the popup doesn't know
_patientLabTestSelected = PatientLabTest.createPatientLabTest( editingContext(), ... );
popup.setPatientLabTest( _patientLabTestSelected );
return popup;
}
// Taken from ModalDialogOpenerExample
public void onCloseModalDialog()
{
// Rebuild the LabTest list
if ( _patientLabTestSelected != null )
updatePatientLabTestList( true );
// And refresh the update container
if ( AjaxRequestHandler.AjaxRequestHandlerKey.equals( context().request().requestHandlerKey() ) )
AjaxUtils._javascript_Response( "labTestUCUpdate();", context());
}
----------------------------------------
AddLabTestPopup.html
<h3>Enter the name of a Lab or Test and select it from the list below.</h3>
<webobject name = "labTestForm">
<webobject name = "labTestsACS"/>
<br/>
<div style="margin-top: 3em;">
<span>Details:</span>
<webobject name = "labTestDetails"/><webobject name = "labTestDetailsOF"/>
</div>
<webobject name = "labTestResultsUC">
<webobject name="selectionName"/>
<br/>
<div>
<webobject name = "addLabTestButton"/>
<webobject name = "closeDialogButton"/>
</div>
</webobject name="labTestResultsUC">
</webobject name="popupForm">
=========================
AddLabTestPopup.wod
labTestForm: ERXWOForm
{
id = "labTestForm";
embedded = true;
}
labTestsACS: AutoCompleteSearch ( AjaxAutoComplete with custom search logic )
{
action = "">
displayStringKeyPath = "displayName";
labelString = "Search Labs and Tests";
limit = 10;
size = 85;
list = allLabsAndTests;
selection = selection;
updateContainerID = "labTestResultsUC";
}
labTestResultsUC: AjaxUpdateContainer
{
id = "labTestResultsUC";
}
labTestDetails: WOText
{
id = "labTestDetails";
value = details;
cols = 50;
rows = 2;
}
labTestDetailsOF: AjaxObserveField
{
observeFieldID = "labTestDetails";
// updateContainerID = "labTestResultsUC";
action = "">
fullSubmit = false;
}
selectionName: WOString
{
value = selection.briefDescription;
valueWhenEmpty = "No Lab or Test Selected";
}
addLabTestButton: YUIButton
{
value = "Add";
useAjax = true;
updateContainerID = "labTestUC"; // Container in the caller component
action = "">
;
disabled = isAddButtonDisabled;
}
closeDialogButton: YUIButton
{
value = "Cancel";
useAjax = true;
;
}
=========================
AddLabTestPopup.java
// Currently just prints out a message when an item is selected
// Without this method, server-side variable doesn't get updated
public WOActionResults selectLabTest()
{
System.out.println( "_selection: " + _selection );
return null;
}
public WOActionResults addLabTestData()
{
if ( _selection == null )
;
else if ( _selection instanceof MedicalLab )
_patientLabTest.setToMedicalLabRelationship( (MedicalLab) _selection );
else
_patientLabTest.setToMedicalTestRelationship( (MedicalTest) _selection );
_patientLabTest.setDetails( _details );
return null;
}