public void Setup(string titleText, FormDataType dType, FormElementEntry entry)
 {
     this.entry    = entry;
     title.text    = titleText;
     originalTitle = titleText;
     dataType      = dType;
     Setup();
 }
        public void Generate(List <FormElementEntry> formElements, bool insertPpidElement)
        {
            if (insertPpidElement)
            {
                ppidElement              = new FormElementEntry();
                ppidElement.displayName  = "Participant ID";
                ppidElement.internalName = "ppid";
                ppidElement.dataType     = FormDataType.String;
                formElements.Insert(0, ppidElement);
            }

            this.formElements = formElements;
            while (contentParent.transform.childCount != 0)
            {
                DestroyImmediate(contentParent.transform.GetChild(0).gameObject);
            }

            List <string> names = new List <string>();

            foreach (FormElementEntry f in formElements)
            {
                if (f.displayName.Replace(" ", string.Empty) == string.Empty)
                {
                    throw new System.Exception("Bad display name in form element");
                }

                if (f.internalName.Replace(" ", string.Empty) == string.Empty)
                {
                    throw new System.Exception("Bad internal name in form element");
                }

                if (!names.Contains(f.internalName))
                {
                    names.Add(f.internalName);
                    GameObject createdElement = CreateElement(f);
                    f.Initialise(createdElement.GetComponent <FormElementController>());
                }
                else
                {
                    throw new System.Exception("Duplicated internal names. They must be unique.");
                }
            }

            if (insertPpidElement)
            {
                // set ppid field to current time
                TextFormController ppidText = (TextFormController)ppidElement.controller;
                ppidText.SetToTimeNow();
            }
        }
        GameObject CreateElement(FormElementEntry formElementEntry)
        {
            switch (formElementEntry.dataType)
            {
            case FormDataType.String:
            case FormDataType.Int:
            case FormDataType.Float:
                return(Instantiate(textPrefab, contentParent.transform));

            case FormDataType.Bool:
                return(Instantiate(checkBoxPrefab, contentParent.transform));

            case FormDataType.DropDown:
                return(Instantiate(dropDownPrefab, contentParent.transform));

            default:
                return(null);
            }
        }