You need to sign in to do that
Don't have an account?
Pooja 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;
}
{
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>
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?
in the page
and in your controller you add a message to the page to be displayed, looks something like this
then return from the controller.
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.
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.
Jill,
We are not using required=true because the display is dynamic. Instead we are attempting to verify the requiredness in the controller.
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
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
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
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.
Message Edited by jyoti on 07-01-2008 01:18 PM
Message Edited by jyoti on 07-01-2008 01:19 PM
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.