Expand my Community achievements bar.

SOLVED

JavaScript how to get / change field (object)TYPE (not access or mandatory)?

Avatar

Level 3

Hello,

I would like to change or at least get the field TYPE of an object/field

Reason: I have a function in my scripting object which should certain things if the given paramter is a button or text field

myFunction(Object){

if (type == button) ....

ClassName is for any use. It just always = field

Could anyone provide some code please?

1 Accepted Solution

Avatar

Correct answer by
Level 10

Hi,

This script might help to show how to get the field type.  I am reasonably show it originally came from Stefan Cameron's website, http://forms.stefcameron.com/, but can not find it now.  Basically if you have a "field" then ui.oneOfChild.className will give you the type of field.

I don't think you will have any luck changing the field type.  I think you will have to have all the field types you want on the form and make them visible when needed.

function listAllFields(node)
{
if (node.className == "exclGroup" || node.className == "subform"  || node.className == "subformSet" || node.className == "area")
{
  for (var i = 0; i < node.nodes.length; i++)
  {
      if (node.name != "ErrorIconSubform")
         {
             var childNode = node.nodes.item(i);
             listAllFields(childNode);
         }
     }
}
else if (node.className == "field")
{
  switch (node.ui.oneOfChild.className)
     {
      case "button":
          console.println("Button:          " + node.somExpression);
          break;

   case "checkButton":
             if (node.parent.className == "exclGroup")
              console.println("RadioButtonList: " + node.somExpression);
             else
              console.println("CheckBox:        " + node.somExpression);
             break;

   case "choiceList":
             var oUITypeNode = node.ui.resolveNode("#choiceList");
             if (oUITypeNode.open == "userControl")
              console.println("DropDownList:    " + node.somExpression);
             else
              console.println("ListBox:         " + node.somExpression);
             break;
  
   case "dateTimeEdit":
             console.println("DateTime:        " + node.somExpression);
             break;

   case "imageEdit":
             console.println("Image:           " + node.somExpression);;
             break;

   case "numericEdit":
             console.println("Numeric:         " + node.somExpression);;
             break;

   case "passwordEdit":
             console.println("Password:        " + node.somExpression);;
             break;

   case "textEdit":
             console.println("Text:            " + node.somExpression);;
             break;

   case "signature":
             console.println("Signature:       " + node.somExpression);;
             break;

   case "barcode":
             console.println("BarCode:         " + node.somExpression);;
             break;

   default:
             // unknown field type
             break;
             }
   }
}

View solution in original post

2 Replies

Avatar

Correct answer by
Level 10

Hi,

This script might help to show how to get the field type.  I am reasonably show it originally came from Stefan Cameron's website, http://forms.stefcameron.com/, but can not find it now.  Basically if you have a "field" then ui.oneOfChild.className will give you the type of field.

I don't think you will have any luck changing the field type.  I think you will have to have all the field types you want on the form and make them visible when needed.

function listAllFields(node)
{
if (node.className == "exclGroup" || node.className == "subform"  || node.className == "subformSet" || node.className == "area")
{
  for (var i = 0; i < node.nodes.length; i++)
  {
      if (node.name != "ErrorIconSubform")
         {
             var childNode = node.nodes.item(i);
             listAllFields(childNode);
         }
     }
}
else if (node.className == "field")
{
  switch (node.ui.oneOfChild.className)
     {
      case "button":
          console.println("Button:          " + node.somExpression);
          break;

   case "checkButton":
             if (node.parent.className == "exclGroup")
              console.println("RadioButtonList: " + node.somExpression);
             else
              console.println("CheckBox:        " + node.somExpression);
             break;

   case "choiceList":
             var oUITypeNode = node.ui.resolveNode("#choiceList");
             if (oUITypeNode.open == "userControl")
              console.println("DropDownList:    " + node.somExpression);
             else
              console.println("ListBox:         " + node.somExpression);
             break;
  
   case "dateTimeEdit":
             console.println("DateTime:        " + node.somExpression);
             break;

   case "imageEdit":
             console.println("Image:           " + node.somExpression);;
             break;

   case "numericEdit":
             console.println("Numeric:         " + node.somExpression);;
             break;

   case "passwordEdit":
             console.println("Password:        " + node.somExpression);;
             break;

   case "textEdit":
             console.println("Text:            " + node.somExpression);;
             break;

   case "signature":
             console.println("Signature:       " + node.somExpression);;
             break;

   case "barcode":
             console.println("BarCode:         " + node.somExpression);;
             break;

   default:
             // unknown field type
             break;
             }
   }
}