keeping focus on field after rule - InfoPath Dev
in

InfoPath Dev

keeping focus on field after rule

Last post 10-25-2006 12:19 AM by zaphi. 5 replies.
Page 1 of 1 (6 items)
Sort Posts: Previous Next
  • 05-17-2006 12:17 PM

    • cde
    • Not Ranked
    • Joined on 05-17-2006
    • Posts 1

    keeping focus on field after rule

    This is probably a simple question for the jscript savvy, but I'm new to coding so here goes.

    1. I've got a text box control with the data type set to integer. The default value is set to 0.

    2. I've assigned a rule to this control that checks the pattern of what the user enters and if it is not an integer, a dialog box will appear with an error message.

    3. After the user closes the error message box, the field is reset to 0 and the cursor then moves to the next field. This is not what I want to happen. I want the cursor to remain on the field until the user either enters a number or leaves it at the default 0.

    So, I'm guessing that I need to set up an 'OnBeforeChange' or 'OnValidate" event that keeps the focus on the field after the error message is closed. Can someone point me to any sample jscript that will help me do this?
  • 05-17-2006 05:10 PM In reply to

    • SamDahl
    • Top 500 Contributor
    • Joined on 03-29-2006
    • Australia
    • Posts 44

    Re: keeping focus on field after rule

    Here's a small sample, basically you need to know which node you want and use the .focus() method.

    function setfocus()
    {
    var myform = document.forms(0);
    var mycntrl = myform.elements(2);

    alert(mycntrl.name);
    mycntrl.focus();
    }
  • 05-17-2006 05:23 PM In reply to

    • SamDahl
    • Top 500 Contributor
    • Joined on 03-29-2006
    • Australia
    • Posts 44

    Re: keeping focus on field after rule

    That example was from a html page. Node selection in InfoPath is more like this:

    var objField1 = XDocument.DOM.selectSingleNode("//my:myFields/my:field1");
  • 10-19-2006 05:57 AM In reply to

    • zaphi
    • Top 150 Contributor
    • Joined on 01-09-2006
    • Switzerland
    • Posts 82

    Re: keeping focus on field after rule

    Hi,
    I have the similar requirement and I tried it as explained. But I receive an error, that the method focus()not supported by the object (node).


    Does anybody can help me?

    Thanks.
    best regards.
    Philippe
    Infopath 2007/SP2
  • 10-23-2006 01:57 PM In reply to

    Re: keeping focus on field after rule

    Hi Zaphi,
    The following code should work for you.
    var objField1 = XDocument.DOM.selectSingleNode("//my:myFields/my:field1"); //Get the node
    XDocument.View.SelectText(objField1); //SelectText method takes the focus to "field1".
  • 10-25-2006 12:19 AM In reply to

    • zaphi
    • Top 150 Contributor
    • Joined on 01-09-2006
    • Switzerland
    • Posts 82

    Re: keeping focus on field after rule

    Hi Agni
    Thanks a lot. Now it's correct.

    Best regards.
    Philippe
    Infopath 2007/SP2
Page 1 of 1 (6 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.