+ Start a Discussion
Rajesh ShahRajesh Shah 

date field in focus on edit page

I have a standard Salesforce edit page where the first 2 fields are picklist and the next one is a date field. Everytime the page loads in edit mode, salesforce automatically brings the date field in focus and the calendar widget pops up. This can be very confusing to the users as the date field is required to be populated only in certain cases. I also do not have the option of moving a text field before the date field.

Is there a way to remove the focus or allow me to have some other field in focus?

Best Answer chosen by Admin (Salesforce Developers) 
CaptainObviousCaptainObvious

If you were to override the standard Edit view with a VisualForce page, there may be a solution...

After building the VF page with the preferred layout, add an window.onload event to set the focus to the field of your choice- something like this:

<script type="text/javascript"> window.onload = setFocus function setFocus() { document.getElementById("{!$Component.myForm.pgBlock.pgBsec.myfield}").focus(); } </script>

 

All Answers

werewolfwerewolf
Yes, that can be annoying.  I'd recommend you change the page layout to move the date field down on the page so that it doesn't get focus when the edit page loads up.
shillyershillyer

Really? I just tried this and I moved the date field below a couple of other fields using the page layout editor and it wasn't in focus anymore. The calendar only popped up once I clicked or tabbed over to the date field.

 

Best,

Sati

werewolfwerewolf

Well, it might be because of the picklist fields -- they might not receive focus normally like an edit box does.

Rajesh ShahRajesh Shah
The date field is after 2 picklist fields. From what I have understood reading the other posts, the first field in the page which is either a text, date, number or maybe Lookup will come into focus. Also I do not have the option of moving the field because there are only 4 editable fields on the page - 2 dropdowns, 1 date and last one is a comment field. I cannot move the comment field above the date field as it messes up the page layout. I guess apart from moving the field there is no other solution possible.
CaptainObviousCaptainObvious

If you were to override the standard Edit view with a VisualForce page, there may be a solution...

After building the VF page with the preferred layout, add an window.onload event to set the focus to the field of your choice- something like this:

<script type="text/javascript"> window.onload = setFocus function setFocus() { document.getElementById("{!$Component.myForm.pgBlock.pgBsec.myfield}").focus(); } </script>

 

This was selected as the best answer
AkiTAkiT

 

<script type="text/javascript">
window.onload = setFocus
function setFocus() {
        document.getElementById("{!$Component.myForm.pgBlock.pgBsec.myfield}").focus();
}
</script>

 ..is a good solution.