dynamically setting required/nillable attribute on textbox

H

Helen

Hi,

I have a drop down list in an infopath form, and based on the value selected
I want to make the next field - a textbox required.

I have created an onafterchange event using js
the if statement works
i.e.
if(XDocument.DOM.selectSingleNode("/my:myFields/my:first_submission/my:group6/my:ddlRequestType").text != "New Requirement")
but I can't seem to find the syntax to assign a required value to the textbox

I have read the xsd, xml and xsl and don't see where these attributes are
saved as other required fields on the page don't differ in syntax from
nonrequired fields

any suggestions?
 
S

S.Y.M. Wong-A-Ton

Try using the ReportError method of the event object in the OnValidate event
for the dropdown and pass the node for the textbox to the ReportError method.
Do something like the following:
---
var node1 = XDocument.DOM.selectSingleNode("my:myFields/my:field1")
var node2 = XDocument.DOM.selectSingleNode("my:myFields/my:field2")

if (node1 != null && node2 != null)
{
if (node1.text != "New Requirement" && node2.text == "")
{
eventObj.ReportError(node2, "required", false);
}
}

Where field1 is the dropdown and field2 the textbox.

NOTE: You do not need custom code to perform field validation; you can set
validation conditions on fields through the design interface of InfoPath.
 
H

Helen

that worked, thank you!

:)

Helen

S.Y.M. Wong-A-Ton said:
Try using the ReportError method of the event object in the OnValidate event
for the dropdown and pass the node for the textbox to the ReportError method.
Do something like the following:
---
var node1 = XDocument.DOM.selectSingleNode("my:myFields/my:field1")
var node2 = XDocument.DOM.selectSingleNode("my:myFields/my:field2")

if (node1 != null && node2 != null)
{
if (node1.text != "New Requirement" && node2.text == "")
{
eventObj.ReportError(node2, "required", false);
}
}

Where field1 is the dropdown and field2 the textbox.

NOTE: You do not need custom code to perform field validation; you can set
validation conditions on fields through the design interface of InfoPath.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top