function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
BDouglasBDouglas 

commandbutton oncomplete breaks apex form

Hi,

 

When I add the oncomplete attribute to my command button my form loses any inputed information.

 

 

<apex:page id="marketingRequestpage" standardController="Contact" extensions="MarketingRequestController" sidebar="false" showheader="false" >

<script type="text/javascript">

function closeForm()
{
alert("Marketing Request Submitted");
// top.window.close();

}

function refreshWindow()
{
opener.location.reload();
}

</script>

<apex:form >

<apex:pageBlock title="{!RequestContact.Name}" id="pbcontact">
<table width="100%" >
<tr>
<td width="25%"><b><apex:outputLabel value="Care Of" for="CareOf"/></b></td>
<td ><apex:inputText id="CareOf" value="{!CareOf}" style="width:200px;height:20px;"/></td>
</tr>
<tr>
<td width="25%"><b><apex:outputLabel value="Street" for="MailingStreet"/></b></td>
<td ><apex:inputTextArea id="MailingStreet" value="{!MailingStreet}" style="width:200px;height:50px;"/></td>
</tr>
<tr>
<td width="25%"><b><apex:outputLabel value="City" for="MailingCity"/></b></td>
<td ><apex:inputText id="MailingCity" value="{!MailingCity}" style="width:200px;height:20px;"/></td>
</tr>
<tr>
<td width="25%"><b><apex:outputLabel value="State" for="MailingState"/></b></td>
<td ><apex:inputText id="MailingState" value="{!MailingState}" style="width:200px;height:20px;"/></td>
</tr>
<tr>
<td width="25%"><b><apex:outputLabel value="Postal Code" for="MailingPostalCode"/></b></td>
<td ><apex:inputText id="MailingPostalCode" value="{!MailingPostalCode}" style="width:200px;height:20px;"/></td>
</tr>
<tr>
<td width="25%"><b><apex:outputLabel value="Country" for="MailingCountry"/></b></td>
<td ><apex:inputText id="MailingCountry" value="{!MailingCountry}" style="width:200px;height:20px;"/></td>
</tr>

<apex:actionRegion >
<tr>
<td width="25%"><b><apex:outputLabel value="Request Type" for="RequestType"/></b></td>
<td> <div class="requiredInput"><div class="requiredBlock"></div>
<apex:selectList id="RequestTypes" value="{!selectrequesttype}" multiselect="false" size="1">
<apex:selectOption itemLabel="-None-"/>
<apex:selectOptions value="{!itemsrequesttype}"/>
<apex:actionSupport event="onchange" action="{!queryMaterials}" rerender="ShippingOption,theTabPanel" />
</apex:selectList></div>
</td>
</tr>

<tr>
<td width="25%"><b><apex:outputLabel value="Shipping Option" for="ShipOption"/></b></td>
<td> <div class="requiredInput"><div class="requiredBlock"></div>
<apex:selectList id="ShippingOption" title="Shipping Option" value="{!SelectShippingOption}" multiselect="false" size="1">
<apex:selectOption itemLabel="-None-"/>
<apex:selectOptions value="{!itemsShippingOption}"/>
<apex:actionSupport event="onchange" action="{!queryMaterials}" rerender="theTabPanel, Notes" />
</apex:selectList> </div>
</td>
</tr>
</apex:actionRegion>
<tr>
<td width="25%"><b><apex:outputLabel value="Ship Date" for="ShipDate"/></b></td>
<td ><div class="requiredInput"><div class="requiredBlock"></div>
<apex:inputField id="ShipDate" value="{!proxyObject.Ship_Date__c}" >
</div>
</apex:inputField>
</td>
</tr>

<tr>
<td width="25%"><b><apex:outputLabel value="Notes" for="Notes"/></b></td>
<td ><apex:inputText id="Notes" value="{!proxyObject.Shipping_Notes__c}" style="width:400px;height:50px;" /></td>
</tr>
<tr>
<td colspan="2"><apex:outputPanel id="pageMessage" rendered="{!showPageMessage}">
<apex:pageMessage title="{!pageMessageTitle}" detail="{!pageMessageDetail}" severity="{!pageMessageSeverity}" strength="{!pageMessageStrength}" escape="false"/>
</apex:outputPanel>
</td>
</tr>

</table>

</apex:pageBlock>

<apex:pageBlock title="Marketing Request Items" id="Items">

<apex:pageBlockButtons >
<apex:commandButton value="Submit" action="{!validateRequest}" oncomplete="closeForm();" rerender="pageMessage"/>
<apex:commandButton value="Clear" action="{!ClearQuantity}" rerender="theTabPanel" />
<apex:commandButton value="Close" onComplete="closeForm();" />
<apex:actionFunction name="SAVEITEMS" action="{!save}" />
</apex:pageBlockButtons>

<apex:tabPanel switchType="client" selectedTab="name2" id="theTabPanel" tabClass="activeTab" inactiveTabClass="inactiveTab">
<style>.activeTab {
background-color: Darkslateblue;

font-weight:bold;
background-image:none
}



.inactiveTab {background-color: lightgrey;
color:black;
background-image:none}

</style>

<apex:tab label="Standard ({!signedTotalQuantity})" name="standardTab" id="tabOne" >
<apex:pageBlockTable value="{!SignedItemsList}" var="signedMaterial" id="StandardItemsTable">
<apex:column headerValue="Project" value="{!signedMaterial.Project__c}" footerValue="Total: {!TotalQuantity}" width="30%"/>
<apex:column headerValue="Quantity" footerValue="Sub Total: {!signedTotalQuantity}" >
<apex:inputField id="qtySigned" value="{!signedMaterial.Quantity__c}" style="width:25px" >
<apex:actionSupport event="onchange" rerender="theTabPanel" />
</apex:inputField>
<script>document.getElementById('{!$Component.qtySigned}').disabled = {!disableInput}; </script>

</apex:column>
<apex:column headerValue="Materials" value="{!signedMaterial.Marketing_Material__c}" />


</apex:pageBlockTable>
</apex:tab>
<apex:tab label="Pre-Odrer ({!preOrderTotalQuantity})" name="preOrderTab" id="tabTwo" >
<apex:pageBlockTable value="{!PreOrderItemsList}" var="preOrderMaterial" id="PreOrderItemsTable">
<apex:column headerValue="Project" value="{!preOrderMaterial.Project__c}" footerValue="Total: {!TotalQuantity}" width="30%"/>
<apex:column headerValue="Quantity" footerValue="Sub Total: {!preOrderTotalQuantity}" >
<apex:inputField id="qtySigned" value="{!preOrderMaterial.Quantity__c}" style="width:25px" >
<apex:actionSupport event="onchange" rerender="theTabPanel" />
</apex:inputField>
<script>document.getElementById('{!$Component.qtySigned}').disabled = {!disableInput}; </script>
</apex:column>
<apex:column headerValue="Materials" value="{!preOrderMaterial.Marketing_Material__c}" width="35%"/>
</apex:pageBlockTable>
</apex:tab>
</apex:tabPanel>


</apex:pageBlock>

<apex:pageBlock title="Signed Offerings" id="SignedOfferings">
<apex:pageBlockTable value="{!SignedOfferings}" var="items" id="ItemsTable">
<apex:column headerValue="" value="{!items.Project_Pursuit__c}" width="35%"/>
</apex:pageBlockTable>
</apex:pageBlock>
<apex:pageBlock title="Pending Offerings" id="PendingOfferings">
<apex:pageBlockTable value="{!PendingOfferings}" var="items" id="ItemsTable">
<apex:column headerValue="" value="{!items.Project_Pursuit__c}" width="35%"/>
</apex:pageBlockTable>
</apex:pageBlock>


</apex:form>


</apex:page>

 

 

public void validateRequest(){
showPageMessage = true;
pageMessageTitle ='Required fields needed.';
pageMessageSeverity ='error';
pageMessageStrength = 2;
pageMessageDetail = '';

if (SelectedRequestType == null ){
pageMessageDetail = pageMessageDetail + 'Request Type ';
showPageMessage = true;
}
if (SelectedShippingOption == null){
pageMessageDetail = pageMessageDetail + '<br> Shipping Option ';
showPageMessage = true;
}
if (mr.Ship_Date__c == null){
pageMessageDetail = pageMessageDetail + '<br> Ship Date ';
showPageMessage = true;
}
if (Totalquantity == 0){
pageMessageDetail = pageMessageDetail + '<br> Quantity Requested ';
showPageMessage = true;
}
if (pageMessageDetail == ''){
save();
showPageMessage = false;
}

}

public PageReference save(){

//Create Signed Request
Marketing__c signedMarketingRequest = marketingRequest;

if (this.signedTotalQuantity > 0){
List<Marketing_Request_Item__c> signedFinalList = new List<Marketing_Request_Item__c>();
insert signedMarketingRequest;
for(Marketing_Request_Item__c item:SignedItemsList) {
if(item.Quantity__c != 0){
item.Marketing_Request__c = signedMarketingRequest.Id;
signedFinalList.add(item);
}
}
insert signedFinalList;
}
//Create Pre-Order Request
if (this.preOrderTotalQuantity > 0){
List<Marketing_Request_Item__c> preOrderFinalList = new List<Marketing_Request_Item__c>();
insert preOrderMarketingRequest;
for(Marketing_Request_Item__c item:PreOrderItemsList) {
if(item.Quantity__c != 0){
item.Marketing_Request__c = preOrderMarketingRequest.Id;
preOrderFinalList.add(item);
}
}

insert preOrderFinalList;
}


return null;

/*

 

 

SteveBowerSteveBower

I wonder if the fact that validateRequest returns a void instead of a pageReference  makes any difference.

 

Does the Javascript console yield any useful errors?

 

It's been awhile since I did this (and the purpose wasn't to resolve onComplete, but I think it would work for you.) I created a "closeThisWindow" VF page which had nothing in it but top.window.close() in a javascript tag.  Then I used the pageReference return value to redirect the user to that VF page.

 

 

Also, the variables in your Select tags are "selectShippingOption" whereas your code is looking at SelectedShippingOption.  (Of course since you haven't posted the whole controller you might have get/sets which are doing the right thing... I just noticed it.)

 

Best, Steve.