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
SBKSBK 

How to make Multiple PageBlocks work independently

I am sure this is a very simple issue and can be solved easily.

 

I have multiple PageBlocks in my VisualForce page...

 

 

<apex:form >

<apex:pageBlock title="New" mode="edit" id="newCampaignPageBlock">

<apex:pageBlockButtons location="bottom">

<apex:commandButton value="Save" action="{!add}" immediate="true"/>

<apex:commandButton value="Cancel" action="{!cancel}" />

</apex:pageBlockButtons>

<apex:pageBlockSection>

.............. 

</apex:pageBlockSection>

</apex:pageBlck>

<apex:pageBlock title="Update" mode="edit" id="updateCampaignPageBlock">

<apex:pageBlockButtons location="bottom">

<apex:commandButton value="Save" action="{!update}" immediate="true"/>

apex:commandButton value="Cancel" action="{!cancel}" />

</apex:pageBlockButtons>

 <apex:pageBlockSection>

..............

</apex:pageBlockSection> 

  </apex:pageBlck>

 

 

 

 

 

 

 

 

 

 One does "Add" and other "Update".

 

 User can do an Add or Update.

 

 In the above code, when the user just wants to update an existing record and does not

 want to do a new, the page complains that some of the required fields for Add are required.

 

 How would I prevent this? 

 

SBKSBK

I put in two different forms, it worked. I am not sure if this the most efficient way of doing it though.

 

I have not tried using "<apex:actionRegion>"..

 

 

paul-lmipaul-lmi
i think the other thing that'd work is ajax enabling your submit button(s) with actionsupport and actionstatus.  you move the server-side method call from the POST action of the button to an onclick javascript event, and it calls the method for the desired form.  in your case, two forms was more required than anything, but you can still make it more slick if you want to.
bob_buzzardbob_buzzard

This is an ideal case for ActionRegions. Simply surround your pageblocks by actionregion tags and only the input elements inside an individual actionregion will be submitted upon click of a button that is also inside the region.

 

Page 169 of the VisualForce Developer's Guide has full information on the actionregion component. 

WesNolte__cWesNolte__c

Hey

 

You can run into issues using multiple forms. Examples of actionregion usage can be found here.

 

Wes