Moving focus to conditionally formatted fields - InfoPath Dev
in

InfoPath Dev

Moving focus to conditionally formatted fields

Last post 12-07-2005 10:54 PM by DavidCrabbe. 6 replies.
Page 1 of 1 (7 items)
Sort Posts: Previous Next
  • 11-28-2005 08:29 PM

    Moving focus to conditionally formatted fields

    I'm having some hassles with moving the focus within my InfoPath form in response to user activity.

    By way of background, there exists a field on the form which contains the monetary cost of an item to be purchased. When the cost is above a certain threshold a purchasing code is to be entered by the user. I have hidden the purchasing code field by conditional formatting until a suitable value is entered to the cost field.

    The problem is that when the user presses the tab key after entering the cost, the focus bypasses the newly displayed field (which logically should be the next field to be filled in) and jumps to next control. How can I get the focus to move to the purchasing code field?

    I've tried thisXDocument.View.SelectText in the OnAfterChange event handler but it falls over - presumably because during execution of the event handler the unhidden field isn't yet part of the View, ie it's still hidden until the event handler has completed.

    OnContextChange doesn't work because the Context is always the evaluated after the change and I can't be sure the focus has changed from the cost field or not.

    Any thoughts, greatly appreciated.
    David.
  • 11-29-2005 06:37 AM In reply to

    Re: Moving focus to conditionally formatted fields

    I was able to create the exact thing you are describing. Maybe someone else has seen this issue before, I have not come across. Going back to .NET WinForms days, and from what I see with my little example, is that Conditional Formatting is not applied until you tab out of the textbox control. When you tab out, it goes to the next visibile control and then conditional formatting is applied.

    To create issue >> create a simple form with a blank data source >> drop on three textboxes >> set conditional formatting on the second >> the conditional formatting rule would be if field1 is blank, hide field2 >> preview the form >> type text into field1 and when you tab you go to field3, not field2.

    I tried doing something like XDocument.View.SelectNodes(XDocument.DOM.selectSingleNode("//my:field2")); in the OnAfterChange event but that will not work either becuase field2 has not been made visible yet. So the OnAfterChange event is being raised before conditional formatting.

    That is as far as I can get right now...
    Jason
    http://www.k2distillery.com/
  • 12-01-2005 07:46 PM In reply to

    Re: Moving focus to conditionally formatted fields

    Thanks for that. Good to see I'm not alone in this issue.
  • 12-01-2005 08:59 PM In reply to

    Re: Moving focus to conditionally formatted fields

    I was hoping someone else would tune in and shed some light...
    Jason
    http://www.k2distillery.com/
  • 12-02-2005 12:25 AM In reply to

    Re: Moving focus to conditionally formatted fields

    I've asked Agni to respond. Some random ideas from me:
    1. Look at Tab Order
    2. Look at OnBeforeAfter
    3. Look at Some kind of special conditional rule (ala Set Field's value)

    Patrick Halstead [InfoPath MVP]
    InfoPathDev
    Patrick Halstead
    Project Manager at Qdabra
  • 12-02-2005 09:15 AM In reply to

    Re: Moving focus to conditionally formatted fields

    Hi,
    One idea is to look for the cost node in OnContextChange event when you tab into cost node, keep this event in a global temp variable called previousContextNode.
    When your OnContextChange event fires for the next time look if the previousContextNode was cost node. If it is cost node use thisXDocument.View.SelectText or thisXDocument.View.SelectNodes to select your newly visible node, because by now your visible event might have fired.

    Another Idea is write an OnAfterChange Event on cost node. In the OnAfterChange method use thisXDocument.View.ForceUpdate(), after this statement use thisXDocument.View.SelectText or thisXDocument.View.SelectNodes to select appropriate node.

    Please post back if any of these solutions work.

    Agni
    InfoPath Dev India
  • 12-07-2005 10:54 PM In reply to

    Re: Moving focus to conditionally formatted fields

    Sorry for the delay in replying.

    I've tested both options and I'm pleased to report that the first suggestion of using OnContextChange works.

    The second suggestion fails when using thisXDocument.View.SelectText because even with the call to thisXDocument.View.ForceUpdate the field isn't yet part of the view.

    Thanks for your help in solving this issue.
    David.
Page 1 of 1 (7 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.