Expand my Community achievements bar.

How to determine whether a field is a TextField, Checkbox, etc

Avatar

Level 9
Hi<br /><br />I need to manipulate fields in a subform recursively.<br /><br />I have the following code that works perfectly...<br /><br />for (var i=0; i<oSubform.nodes.length; i++) {<br /> var oObject = oSubform.nodes.item(i);<br /> if (oObject.className == "field") {<br /> // do stuff<br /> } else if (oObject.className == "subform") {<br /> // do some other stuff<br /> }<br />}<br /><br />The problem is the "className" equals "field" for almost any type of field - checkbox, radio, textfield, numeric field, etc. We need to do slightly different things depending on the type of field.<br /><br />Does anyone know if there's a way to determine the "field-type"?<br /><br />Many thanks,<br />Howard
4 Replies

Avatar

Former Community Member
Howard, you'll need to test the className of the only child of the field's ui node. For example on a textfield:



TextField1.ui.oneOfChild.className



returns TextEdit.



I won't go into the different values for all the fields, but the easy way to see them is to drag a field onto a form and look at the XML source to see the name of node.



P.S. You didn't mention what event you were running your script in, but initialize will be too early as the node has not been created yet. form:ready or layout:ready will work fine.



Chris

Adobe Enterprise Developer Support

Avatar

Former Community Member
Howard,



I found this sample form that has a script on it that may help. When you open in Acrobat hit Ctrl-J to open the console, and then click the Check Fields button. Open in Designer to see the script on the button.



Chris

Adobe Enterprise Developer Support

Avatar

Level 9
Thanks Chris



One further question: how do you KNOW to use oneOfChild - it's entirely unobvious to me. We tried TextField1.ui.className and several other variations, but of course those didn't work.



Many thanks,

Howard

Avatar

Former Community Member
Well, I know from experiance and playing around with the XML of forms for a while. But to really KNOW, you could look at the XFA spec for the ui element to see that you're interested in the oneOfChild to see what the field is. Here's an excert from p. 555 of the 2.2 spec, discussing the ui element:



"This element has a set of one-of properties. The choice of one-of property determines the type of widget displayed. For example, if the button property is included the content will be displayed as a button

widget. This determines both the appearance of the content and the interaction with it. Including the defaultUiproperty delegates the decision about what widget to use to the XFA application."



Chris

Adobe Enteprise Developer Support