locked
setFocus() doesn't work RRS feed

  • Question

  • I try to set the focus on the description field of a support task or an email and it doesn't work any more after UR13

    var control = Xrm.Page.ui.controls.get("description");
    control.setFocus();

    I don't get any error messages, it just doesn't work.

    Any suggestions ?

    Thanks



    • Edited by _cram Tuesday, May 21, 2013 4:26 PM
    Tuesday, May 21, 2013 4:26 PM

Answers

  • If you've made sure that the attribute is visible, not disabled and in a section that is visible and a tab that is visible - it could be that CRM is enforcing the subject being the first field to have focus.

    You could try putting the set focus in a setTimeout so that it fires after the onload event.


    Scott Durow
    Read my blog: www.develop1.net/public     Follow Me on Twitter
    If this post answers your question, please click "Mark As Answer" on the post and "Mark as Helpful"

    • Marked as answer by _cram Thursday, May 23, 2013 9:26 AM
    Wednesday, May 22, 2013 9:47 PM
    Answerer

All replies

  • Try:

    Xrm.Page.getAttribute("description").controls.get(0).setFocus();

    hth


    Scott Durow
    Read my blog: www.develop1.net/public     Follow Me on Twitter
    If this post answers your question, please click "Mark As Answer" on the post and "Mark as Helpful"

    Tuesday, May 21, 2013 4:54 PM
    Answerer
  • SetFocus will cause an error if used on a control that is disabled, not visible or can not accept focus.


    My Weblog | My Website

    Tuesday, May 21, 2013 5:00 PM
    Moderator
  • I have tried 

    Xrm.Page.getAttribute("description").controls.get(0).setFocus();

     and it does not work. always the focus is set on the subject field

    Thanks

     
    Tuesday, May 21, 2013 5:05 PM
  • Hi,

    Please try below code:

    Xrm.Page.getControl("attributename").setFocus(true);

    Wednesday, May 22, 2013 2:20 AM
  • Hi,

    Please use this

    Xrm.Page.getControl("name").setFocus(true); Xrm.Page.getControl("TheFieldYouReallyWantToFocus").setFocus(true);

    if you find it useful please vote for my answer.

    thank you


    vasubabuk

    Wednesday, May 22, 2013 4:21 AM
  • Xrm.Page.getAttribute("fieldname").controls.get(0).setFocus();

    Your field should be enabled on form.


    If you find this post helpful then please "Vote as Helpful" and "Mark As Answer". Thanks and Regards, Yogesh Vijay Mulay

    Wednesday, May 22, 2013 4:33 AM
  • I have tried all the above and none works.

    The only way to make it focus on the description field is if  I make the 'subject' field read only on the form. But this is not the right solution.

    Thanks

    Wednesday, May 22, 2013 9:12 AM
  • Please check if you have any other script which causes an issue. once it is corrected it will work.

    • Proposed as answer by Subhash Mahato Wednesday, May 22, 2013 11:25 AM
    Wednesday, May 22, 2013 11:25 AM
  • There is only one script running on the onload event

    Thanks


    • Edited by _cram Wednesday, May 22, 2013 12:14 PM
    Wednesday, May 22, 2013 12:14 PM
  • If you've made sure that the attribute is visible, not disabled and in a section that is visible and a tab that is visible - it could be that CRM is enforcing the subject being the first field to have focus.

    You could try putting the set focus in a setTimeout so that it fires after the onload event.


    Scott Durow
    Read my blog: www.develop1.net/public     Follow Me on Twitter
    If this post answers your question, please click "Mark As Answer" on the post and "Mark as Helpful"

    • Marked as answer by _cram Thursday, May 23, 2013 9:26 AM
    Wednesday, May 22, 2013 9:47 PM
    Answerer
  • Thanks 

    I have used setFocus and setTimeout functions together and works.

    Thursday, May 23, 2013 9:27 AM