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
Bhaskar525Bhaskar525 

<apex:selectlist> field level validation

Hi friends,

 

i designed one application in that insted of multipicklist i used <apex:selectlist> tag to capture the information (for clientside view). i created one validation rule for that picklist using apex code.when validation occure it shows on the top of the page (apex:pagemessage). Is there any way to show at field level when validation occure. 

 

Best Answer chosen by Admin (Salesforce Developers) 
DharshniDharshni

You can try the following code :

<apex:outputpanel >
                    <apex:SelectList value="{!var}" >
                        <apex:selectOptions value="{!values}"></apex:selectOptions>
                        <apex:actionSupport event="onchange" action="{!someaction}" />
                    </apex:SelectList><br/>
                    <font color="red">              
                        <apex:outputText id="errMsg" value="Enter a value" rendered="{!varError}"/>
                    </font>
</apex:outputpanel>

 

On submitting the form, catch the validation error in your controller and set the variable - varError to true.

All Answers

Navatar_DbSupNavatar_DbSup

Hi,

 

In the Vf page display the validation error message on the field level for this you can create a string type property in the your controller and assign the error message in that property in catch block after that bind the property with the output label on the page below your Picklist and reRender output label on the command button link.

 

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved. 

 

Bhaskar525Bhaskar525

Dear Navatar,

 

If you don't mind could you please provide sample code how to validate. i didn't get how to work on it.

 

Thanks,

Bhaskar

DharshniDharshni

You can try the following code :

<apex:outputpanel >
                    <apex:SelectList value="{!var}" >
                        <apex:selectOptions value="{!values}"></apex:selectOptions>
                        <apex:actionSupport event="onchange" action="{!someaction}" />
                    </apex:SelectList><br/>
                    <font color="red">              
                        <apex:outputText id="errMsg" value="Enter a value" rendered="{!varError}"/>
                    </font>
</apex:outputpanel>

 

On submitting the form, catch the validation error in your controller and set the variable - varError to true.

This was selected as the best answer
Bhaskar525Bhaskar525

Dear Dharshi,

 

Thanks for providing sample code. it give some idea to do my work. 

 

Thanks,

Bhaskar.