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
angusgrantangusgrant 

visualforce SelectList validation error to replicate Inputfield functionality

 I am using the <apex:selectlist> visualforce Tag and wish to replicate the behaviour of the standard tag for validation <apex:InputField>. My SelectList is a required field in filling out the form.

 

The moment the validation error that is returned reads the following: 

"j_id0:StdOXCEITemplate:j_id9:j_id37:j_id49:j_id50:smileysurprised:rg: Validation Error: Value is required."

 

1. My first task will be to create a customise this message to read "You must input a value for thie picklist field division"
2. Will be to replicate the css to make sure the selectList value is displayed with the red left border to show it is required.

3. Will be to make sure that the field is highlited in red in the sameway as it does for the inputfield  with the error message next to field specifying that it is required.

 

Unfortunatly the only one I have any idea on how to implement is the 2nd bullet. Can anyone advise on how this is done?

 

 

<apex:pageBlockSectionItem >
<apex:outputLabel value="Organisation" for="org"></apex:outputLabel>
<apex:selectList value="{!picklistValue}" required="true" multiselect="1" size="1" id="org">
<apex:SelectOptions value="{!OrganisationNames}"></apex:SelectOptions>
<apex:actionSupport event="onchange" rerender="thePageBlock"/>
</apex:selectList>
</apex:pageBlockSectionItem>

S_LieS_Lie

1. Use the validation in the apex class, put the ApexMessages :

JPlayEHRJPlayEHR

I need to do this same thing.  Could you post some sample code to show how you accomplished this (or at least how you accomplished #2)? Thanks! :robothappy:

FODONFODON

You can add a label to the SelectList. The message will then use the label value instead of the ugly Salesforce field ID.

 

"Organisation:  Validation Error: Value is required."

 

Instead of

 

"j_id0:StdOXCEITemplate:j_id9:j_id37:j_id49:j_id50rg: Validation Error: Value is required." 

 

To use Label parameter in SelectList, you will need to ensure the Page Metadata API is greater or equal to 23.

 

Modified Code

 

<apex:pageBlockSectionItem >
<apex:outputLabel value="Organisation" for="org"></apex:outputLabel>
<apex:selectList value="{!picklistValue}" required="true" multiselect="1" size="1" id="org" label="Organisation">
<apex:SelectOptions value="{!OrganisationNames}"></apex:SelectOptions>
<apex:actionSupport event="onchange" rerender="thePageBlock"/> 
</apex:selectList>
</apex:pageBlockSectionItem>

 


Bhaskar525Bhaskar525

Dear FODON,

 

          Is it possiable to show the error message at field level for client friendly view. If there is a way please give me some code sample.

 

Thanks,

Bhaskar

 

 

FODONFODON

Hi Bhaskar,

 

I have not been able to show the error message at field level. I tried a few things including some hidden HTML but did not work. Becuase it was not a must have for my project I did not waste any time on it.

 

Regards,

 

Finbarr O'Donoghue.

Bhaskar525Bhaskar525

Dear Fodon,

 

Thanks for your resonse.

 

 

Thanks,

Bhaskar.