You need to sign in to do that
Don't have an account?
How to return to previous page if validation fails?
On the Opportunity page, I've a VF page which generates a selection list based on some criteria and a button to submit based on a similar criteria (both select list will be enabled or disabled as well).
Now when they submit the form, my Apex code is as follow:
public PageReference createOrderSFA() { String newPageUrl = SFAURL+'?sfdcid='+oppor.Id+'&sfdcsubregion='+selectedRegion; PageReference newPage = new PageReference(newPageUrl); newPage.setRedirect(true); return newPage; }
But I want to check if selectedRegion is null, I want to cancel the submit and stay on the current page (the Opportunity page).
How do I do it?
I tried returning null upon checking for selectedRegion, but it loads the VF page instead.
Also, how to I reference an element (SFA_item) on the VF page?
<apex:page id="SFA_page" standardController="Opportunity" extensions="SfaOrderExtension"> <apex:form id="SFA_form" target="SFAWINDOW"> <apex:selectList id="SFA_item" disabled="{!selectListState}" value="{!subRegions}" size="1" multiselect="false" styleClass="opporSubregionStyle"> <apex:selectOptions value="{!items}" /> </apex:selectList> <apex:commandButton value="Create Order" action="{!createOrderSFA}" disabled="{!buttonState}" onclick="return checkOrderEntered()" /> </apex:form> </apex:page>
Based on this,
http://developinthecloud.wordpress.com/2009/06/17/visualforce-component-ids-javascript/
I tried:
var theItem = document.getElementById('{!$Component.SFA_item}');
but it is actually (empty). I'm using document.getElementById('SFA_page:SFA_form:SFA_item') now, but would like to know the proper method.
Thanks.