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
lakshman.mattilakshman.matti 

Need to scroll back to error messages in VF page

HI All,

I have created a visualforce page which contains many inputfileds to accept values from user. i'm showing some visualforce error messages on top of the page, if user forgets to enter values in inputfields. 
what i want here is whenever user enters some values and clicked on submit button,if it shows any errors it should automatically go back to the the place where error messages are displyed.(i.e we need to set focus on Error messages.)
I hope my question is clear.
Any suggestions or code snippet is appriciated.


Thanks
Lakshman


 
Mahesh DMahesh D
Hi Lakshman,

Please find the below:

You can use the 

<apex:message> tag.
 
<apex:page controller="TestMessageController">
	<apex:form >
		<apex:outputLabel value="Test String" /><apex:inputText value="{!test.Name}" id="test"/>
		<br/><apex:message for="test"/>
	</apex:form>
</apex:page>
 
public class TestMessageController{
    public Account test{get;set;}
    public TestMessageController(){

    }
}

Also look into other options provided here:

http://jessealtman.com/2013/08/difference-between-the-multiple-messaging-options-in-visualforce/

http://www.sfdcpoint.com/salesforce/show-error-message-visualforce-page/

https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/apex_pages_message.htm


Please do let me know if it helps you.

Regards,
Mahesh
 
Naval Sharma4Naval Sharma4
Hi Laxman,

In order to achieve this in your page you have to add a javascript code that needs to be rerender on onComplete call of your commandbutton.
 
<apex:outputPanel id="jsCode">
    <script>
        $(function(){
            var divID = '.' + classOfPageMessage/Div;
            $('html, body').animate({
                scrollTop: $(divID).offset().top
            }, 2000);
        });
    </script>
</apex:outputPanel>

put "jsCode" in the rerender property of commandbutton.
lakshman.mattilakshman.matti
Hi Naval Sharma,
Thanks for you reply.
Can you tel me what i have to in place of ClasOfPAgeMessage in the above script.

If you dont mind can you post full code of vf page.
Thanks in advance.
 
lakshman.mattilakshman.matti
Hi Naval sharma,

Can you please post some code snippet.waiting for your response.
it's urgent buddy..:)

Thanks
Lakshman