0

I have a visual force page that has a date field that kept stealing the focus no matter what order the field was in and despite using <script>function setFocusOnLoad(){}</script>.

I used windowOnLoad() to change the focus and that worked, however whenever a command button is clicked or lookup is used for a field the focus goes back to the same date field even if it is filled in. The buttons refresh some panels, but not the block that the date field is in so I don't know why the field keeps getting focus. The field has no properties in the visual force page that would change the focus.

Is there an event after panels/blocks are hidden/shown that would put focus on the field?

4
  • That's a really weird issue. Can you post your page here? Commented May 11, 2015 at 16:33
  • Page code The basic idea is to try and remove focus from id=CallDateField and switch it to id=fopportunity. Overriding onLoad will remove focus when the page loads but will keep switching focus back to it when any buttons are pressed.
    – Cameron
    Commented May 11, 2015 at 18:11
  • Alternativelink in case that one doesn't work
    – Cameron
    Commented May 11, 2015 at 18:19
  • Have you checked if any of the Kendo JS is setting focus? Commented May 11, 2015 at 18:21

1 Answer 1

2

I think it happened because you have overwritten standard salesforce onload events. Try the method in below link,

http://bobbuzzard.blogspot.com/2011/05/onload-handling.html

Basically it helps you to execute both standard onload script and your own script.

3
  • You're right in that if window.onload() isn't overwritten than the date field won't receive focus after every page change. But your solution to add to the load event doesn't stop the date window from appearing, though the cursor does move to the field I'm trying to give focus too.
    – Cameron
    Commented May 11, 2015 at 17:41
  • In that in the place to add your own onload event, you need to select some other field in the visualforce page and set focus to that. document.getElementById("page:form:myElement").focus();
    – Victor
    Commented May 11, 2015 at 17:46
  • getElementByID.focus() only changes where the cursor goes. It doesn't stop the date picker from opening.
    – Cameron
    Commented May 11, 2015 at 23:03

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .