Programmatic Selection in InfoPath

來源:互聯網
上載者:User
 

InfoPath supports two methods on the View OM object - "SelectText" for data entry controls and "SelectNodes" for structural controls - in order to enable programmatic selection.

Data entry controls that can be programmatically selected (using View.SelectText):

  • Text Box
  • Rich Text Box
  • Date Picker

Structural controls that can be programmatically selected (using View.SelectNodes):

  • Optional Section
  • Choice Section
  • Repeating Section (items)
  • Repeating Table (rows)
  • Repeating Recursive Section (items)
  • Bulleted, Numbered & Plain List
  • File Attachment

Programmatically setting focus to these controls is not supported:

  • Drop-Down List Box
  • List Box
  • Check Box
  • Option Button
  • Button
  • Picture (Linked or Included)
  • Ink Picture
  • Hyperlink
  • Expression Box / Vertical Label
  • ActiveX
  • Section

Examples:

Steps to select rows in a repeating table using SelectNodes:

In order to set selection extending the 1st two rows of a repeating table you can do the following steps:

1. Insert a "repeating table" from the controls task pane

2. Insert a "button" from the controls task pane

3. Double click on the button control to bring up Button Properties

4. Click on the "Edit Form Code" button

[you may be asked to install Microsoft Script Editor if you don't already have it installed]

5. This should bring up script.js file in Microsoft Script Editor with a function such as

function

CTRL5_5::OnClick(eventObj)

{

// Write your code here

}

6. Insert the following code inside the above function

var nodeSelStart = XDocument.DOM.selectSingleNode("/my:myFields/my:group1/my:group2[1]")

var nodeSelEnd = XDocument.DOM.selectSingleNode("/my:myFields/my:group1/my:group2[2]")

XDocument.View.SelectNodes(nodeSelStart, nodeSelEnd)

[This assumes that the repeating table is bound to my:group2. You can figure the XPath by looking at the Data Source task pane after selecting the appropriate repeating table.]

7. Now you should be able to preview the form and verify that clicking on the button causes the expected selection. Please note that you have to have at least two rows in the table in order to select the first two rows. Otherwise you will see an error.

Steps to select text in a text box using SelectText:

In order to select text in a text box you can do the following steps:

1. Insert a "text box" from the controls task pane

2. Insert a "button" from the controls task pane

3. Double click on the button control to bring up Button Properties

4. Click on the "Edit Form Code" button

[you may be asked to install Microsoft Script Editor if you don't already have it installed]

5. This should bring up script.js file in Microsoft Script Editor with a function such as

function

CTRL2_5::OnClick(eventObj)

{

// Write your code here

}

6. Insert the following code inside the above function

var nodeSelText = XDocument.DOM.selectSingleNode("/my:myFields/my:field1")

XDocument.View.SelectText(nodeSelText)

[This assumes that the text box is bound to my:field1. You can figure the XPath by looking at the Data Source task pane after selecting the appropriate text box.]

7. Now you should be able to preview the form and verify that clicking on the button causes the expected selection.

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.