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
Pooja ShahPooja Shah 

Static Resource for validation - error

I want to validate the form (which has 4 sets of radio buttons) to ensure all the radio buttons are selected.
if each of the 4 has  a radio button selected, then It moves to the next page as expected but gives an alert which it should not.
if all are not selected, it stays on the same page but the page gets refreshed, so we lose the previously answere questions.
 
 
function checkSelectedApprovers(inputForm)
{
 var processForm = true;
 for(var inputFormFieldsIndex = 0; inputFormFieldsIndex < inputForm.elements.length; inputFormFieldsIndex++)
 {
  
  if(!inputForm.elements[inputFormFieldsIndex].checked)
  {
   
   window.alert("Please select an Approver from each group!");
   inputForm.elements[inputFormFieldsIndex].focus();
   processForm = false;
   return processForm;
  }   
  
 }
 return processForm;
}
 
In the page

<apex:commandButton value="Continue" action="{!nextPage}" onclick="return checkSelectedApprovers(this.form)"/>

<apex:commandButton value="Continue" action="{!nextPage}"/>

</apex:pageBlock>

</apex:form>

<script language="Javascript" type="text/javascript" src="{!$Resource.SelectApproverValidation2}">

</script>

</apex:page>

Ron HessRon Hess
why not validate the fields are filled in in your controller , that way all your logic is in one place.
I don't know why your javascript is not working as expected, but the action will be called either way the onclick evaluation won't change the call to the action

so you have two things going on when you click, the action AND the javascript.

also , looks like you have two identical buttons, why?
Pooja ShahPooja Shah
The same button twice was a mistake. I removed it.
But my javascript doesnt work anyways.
 
If i include this logic in the controller class, how can I give a alert to the user saying that please select one option from each of the lists?
 
 
Pooja
Ron HessRon Hess
i believe you use <apex : messages />
in the page

and in your controller you add a message to the page to be displayed, looks something like this

ApexPages.Message msg;
msg = new ApexPages.Message(ApexPages.Severity.ERROR,'messaggeText');
ApexPages.addMessage(msg);

then return from the controller.
jyotijyoti
Ron,
 
Instead of the custom error message appearing as defined in the ApexPages.Message
 
ApexPages.Message msg;

msg = new ApexPages.Message(ApexPages.Severity.ERROR,'You must select one person from each group!');

ApexPages.addMessage(msg);

a standard validation rule is appearing: j_id0:j_id1:selectApprover1:j_id7: Validation Error: Value is required.

Any thoughts?

Thanks.

 

 

 

jwetzlerjwetzler
Are you using required="true"?  That gives you some standard validation and will not allow you to submit the form without a value for those fields.  However if you are going to do that validation in your controller, in this case because you want to provide a different error message, then you don't need required="true".

Remove that and see if it works.  Otherwise please post your code (or if your page is long a smaller, working example) and please use the SRC button when posting it.
jyotijyoti

Jill,

We are not using required=true because the display is dynamic.  Instead we are attempting to verify the requiredness in the controller.

Code:
public PageReference nextPage() 

{ 

 if((financeSection == true && financeMember == null) || (pricingSection == true && pricingMember == null) || (controllershipSection == true && controllershipMember == null))
 {
  ApexPages.Message msg;
  msg = new ApexPages.Message(ApexPages.Severity.ERROR,'You must select one person from each group!'); 
  ApexPages.addMessage(msg);
  PageReference pr = Page.select_approver1;
  pr.getParameters().put('contractId', System.currentPageReference().getParameters().get('contractId'));
  pr.setredirect(true);
  return pr;
 }
 else condition omitted
}

 
In the page, we are just referencing the tag:

<apex:messages/>



Message Edited by jyoti on 07-01-2008 12:27 PM

Message Edited by jyoti on 07-01-2008 12:29 PM
jwetzlerjwetzler
Please post your page code as well.  It does not help for me to see your controller code without your page code.

However you are setting a message and then redirecting the user to a page, so there is no way that your message is going to show up.  Generally if you are going to add a message you want to return null and then rerender the portion of your page that contains the messages component.


Message Edited by jwetzler on 07-01-2008 09:30 AM
jyotijyoti
Code:
<apex:page controller="select_Approver1" action="{!getContractTerms}">

<apex:pageBlock title="Approval Step 1">

    <apex:form id="selectApprover1"> 
  
        <h1>Based on the information you have entered, the Deal Protocol team has determined that you require approval from the following groups.  Please select one person from the following groups.</h1>

        <p></p>
  <apex:messages/>
        <apex:outputPanel rendered="{!showFinanceSection}">
        <apex:outputLabel ><h1>Finance</h1></apex:outputLabel>  
        <apex:selectRadio value="{!financeMember}" required="true" layout="pageDirection">
        <apex:selectOptions value="{!RadioButtonsFinance}"/><br/></apex:selectRadio>
        </apex:outputPanel>
        
        <p></p>
        <apex:outputPanel rendered="{!showPricingSection}">
        <apex:outputLabel ><h1>Pricing</h1></apex:outputLabel>  
        <apex:selectRadio value="{!pricingMember}" required="true" layout="pageDirection">
        <apex:selectOptions value="{!RadioButtonsPricing}"/><br/></apex:selectRadio>
        </apex:outputPanel>
        
        <p></p>
        <apex:outputPanel rendered="{!showControllershipSection}">
        <apex:outputLabel ><h1>Controllership</h1></apex:outputLabel>  
        <apex:selectRadio value="{!controllershipMember}" required="true" layout="pageDirection">
        <apex:selectOptions value="{!RadioButtonsControllership}"/><br/></apex:selectRadio>
        </apex:outputPanel>
        
        <p></p>  
        <p></p>
 <apex:commandButton value="Continue" action="{!nextPage}"/>
    </apex:form >

</apex:pageBlock>

</apex:page>

 

The error message shows up but it seems to be a standard one rather than the custom one we want to display.

Thanks.
 



Message Edited by jyoti on 07-01-2008 12:34 PM
jwetzlerjwetzler

jyoti wrote:

We are not using required=true because the display is dynamic.



Huh?  You have required="true" for each selectRadio component!

You need to remove them, and also you need to make the change to the redirect like I mentioned in my previous post.
jyotijyoti
Yes that is because we were trying to use that for requiredness.
 
Returning null in the pageReference does not display the error message either.  There is one other piece we're missing.
 
Code:
    public PageReference nextPage() 
    {    
        if((financeSection == true && financeMember == null) || (pricingSection == true && pricingMember == null) || (controllershipSection == true && controllershipMember == null))
        {
            ApexPages.Message msg;
            msg = new ApexPages.Message(ApexPages.Severity.ERROR,'You must select one person from each group!');
            ApexPages.addMessage(msg);
            return null;
        }
    }

 


Message Edited by jyoti on 07-01-2008 01:18 PM

Message Edited by jyoti on 07-01-2008 01:19 PM
jwetzlerjwetzler
Right, but that is what's giving you the standard error message instead of the one you specified.  That's what I was trying to tell you and why I asked you to remove it.

And you're returning null but are you rerendering the section of your page that shows the messaging component?  You need that so that you'll actually refresh the portion of your page that is showing the message.