示例#1
0
    public static void WriteGPSHTMLField(FormFieldExport FormF, bool isEditMode, List<ResponseValue> responseValues,
        ref string fieldLabel,
        List<string> ngModelName,
        ref string filedBody,
        ref string constr,
        Dictionary<int, string> constraint,
        ref string outVal,
        Literal ltlScript,
        ref string repVal,
        Dictionary<int, string> roaster,
        Dictionary<int, string> table,
        Dictionary<string, string> ngModelNameSubForm,
        ref string model
        )
    {
        try
        {
            if (FormF.FormFieldParentID == null)
            {
                fieldLabel = FormF.label;
                ngModelName.Add(FormF.name);
                filedBody +=
                    " <input type=\"number\" class=\"col-xs-5 col-sm-4\" min=\"-90\" max=\"90\" step=\"any\" " +
                            "ng-model=\"" + model + FormF.name + "LatDE\"";
                constr = "";
                if (constraint.TryGetValue((int)FormF.id, out constr))
                {
                    filedBody += constr;
                }
                filedBody += " name=\"r_" + FormF.name + "LatDE\"";

                var fieldVal = "";
                if (isEditMode)
                {
                    fieldVal = (from v in responseValues
                                where v.formFieldId == FormF.id
                                select v.value).FirstOrDefault();
                    if (fieldVal != null)
                    {
                        filedBody += " ng-init=\"" + model + FormF.name + "LatDE=" +
                                     fieldVal.ToString().Split(' ')[1] + "\" ";
                    }
                }

                if (FormF.required == 1)
                {
                    if (!string.IsNullOrEmpty(outVal))
                    {
                        ltlScript.Text += "$scope." + model + FormF.name + "LatDE = 0;";
                        filedBody += " ng-required=\"currForm" + Regex.Match(outVal, "currForm(.+?)\">").Groups[1].Value +
                                     "\" />\n";
                    }
                    else filedBody += " required />\n";
                    filedBody += "<span style=\"color: #f1c409; padding: 5px;\" ng-show=\"mainForm.r_" + FormF.name +
                                 "LatDE.$error.required || mainForm.r_" + FormF.name +
                                 "LatDE.$error.number\"><i class=\"fa fa-warning\"></i></span> \n";
                }
                else filedBody += "/>";

                filedBody +=
                    " <input type=\"number\" class=\"col-xs-5 col-sm-4\" step=\"any\" min=\"-180\" max=\"180\" ng-model=\"" +
                    model + FormF.name + "LongDE\"";
                constr = "";
                if (constraint.TryGetValue((int)FormF.id, out constr))
                {
                    filedBody += constr;
                }
                filedBody += " name=\"r_" + FormF.name + "LongDE\"";

                if (isEditMode
                    && fieldVal != null)
                {
                    filedBody += " ng-init=\"" + model + FormF.name + "LongDE=" + fieldVal.ToString().Split(' ')[0] + "\" ";
                }

                if (FormF.required == 1)
                {
                    if (outVal != null && outVal != "")
                    {
                        ltlScript.Text += "$scope." + model + FormF.name + "LongDE = 0;";
                        filedBody += " ng-required=\"currForm" + Regex.Match(outVal, "currForm(.+?)\">").Groups[1].Value +
                                     "\" />\n";
                    }
                    else filedBody += " required />\n";
                    filedBody += "<span style=\"color: #f1c409; padding: 5px;\" ng-show=\"mainForm.r_" + FormF.name +
                                 "LongDE.$error.required\"><i class=\"fa fa-warning\"></i></span>";
                    filedBody += "<span style=\"color: red; padding: 5px;\" ng-show=\"mainForm.r_" + FormF.name +
                                 "LongDE.$error.number\"><i class=\"fa fa-warning\"></i></span> \n";
                }
                else filedBody += "/>";
                filedBody += "<span style=\"color: red; padding: 5px;\" ng-show=\"mainForm.r_" + FormF.name +
                             "LatDE.$error.min || mainForm.r_" + FormF.name +
                             "LatDE.$error.max\"><i class=\"fa fa-warning\"></i>Invalid Coords!</span>\n";
                filedBody += "<span style=\"color: red; padding: 5px;\" ng-show=\"mainForm.r_" + FormF.name +
                             "LongDE.$error.min || mainForm.r_" + FormF.name +
                             "LongDE.$error.max\"><i class=\"fa fa-warning\"></i>Invalid Coords!</span>\n";
                filedBody += " \n";
            }
            else //s* i think this else is useless
            {
                repVal = "";
                roaster.TryGetValue((int)FormF.FormFieldParentID, out repVal);
                if (repVal == null)
                    table.TryGetValue((int)FormF.FormFieldParentID, out repVal);

                fieldLabel = FormF.label;
                filedBody += "Lat: <input type=\"number\" step=\"any\" min=\"-90\" max=\"90\" ng-model=\"rb_" + repVal + "." +
                             FormF.name + "LatDE\"";
                ngModelNameSubForm.Add(FormF.name, "rb_" + repVal + ".");
                if (FormF.isReadOnly == 1 ||
                    FormF.calculated == 1)
                {
                    filedBody += " ng-readonly=\"1\" ";
                }
                constr = "";
                if (constraint.TryGetValue((int)FormF.id, out constr))
                {
                    filedBody += constr;
                }
                filedBody += " name=\"r_" + FormF.name + "LatDE\"";
                if (FormF.required == 1)
                {
                    if (!string.IsNullOrEmpty(outVal))
                    {
                        filedBody += " ng-required=\"currForm" + Regex.Match(outVal, "currForm(.+?)\">").Groups[1].Value +
                                     "\" />\n";
                    }
                    else filedBody += " required />\n";
                    filedBody += "<span style=\"color: #f1c409; padding: 5px;\" ng-show=\"subForm" + repVal + ".r_" +
                                 FormF.name + "LatDE.$error.required\"><i class=\"fa fa-warning\"></i></span>";
                    filedBody += "<span style=\"color: red; padding: 5px;\" ng-show=\"subForm" + repVal + ".r_" +
                                 FormF.name + "LatDE.$error.number\"><i class=\"fa fa-warning\"></i></span>\n";
                }
                else filedBody += "/>";

                filedBody += " Long: <input type=\"number\" step=\"any\" min=\"-180\" max=\"180\" ng-model=\"rb_" + repVal + "." +
                             FormF.name + "LongDE\"";
                ngModelNameSubForm.Add(FormF.name, "rb_" + repVal + ".");
                if (FormF.isReadOnly == 1 || FormF.calculated == 1)
                {
                    filedBody += " ng-readonly=\"1\" ";
                }
                constr = "";
                if (constraint.TryGetValue((int)FormF.id, out constr))
                {
                    filedBody += constr;
                }
                filedBody += " name=\"r_" + FormF.name + "LongDE\"";
                if (FormF.required == 1)
                {
                    if (outVal != null && outVal != "")
                    {
                        filedBody += " ng-required=\"currForm" + Regex.Match(outVal, "currForm(.+?)\">").Groups[1].Value +
                                     "\" />\n";
                    }
                    else filedBody += " required />\n";

                    filedBody += "<span style=\"color: #f1c409; padding: 5px;\" ng-show=\"subForm" + repVal + ".r_" +
                                 FormF.name + "LongDE.$error.required\"><i class=\"fa fa-warning\"></i></span>";
                    filedBody += "<span style=\"color: red; padding: 5px;\" ng-show=\"subForm" + repVal + ".r_" +
                                 FormF.name + "LongDE.$error.number\"><i class=\"fa fa-warning\"></i></span>\n";
                }
                else filedBody += "/>";
                filedBody += "<span style=\"color: red; padding: 5px;\" ng-show=\"subForm" + repVal + ".r_" + FormF.name +
                             "LatDE.$error.min || subForm" + repVal + ".r_" + FormF.name +
                             "LatDE.$error.max\"><i class=\"fa fa-warning\"></i>Invalid coords!</span>\n";
                filedBody += "<span style=\"color: red; padding: 5px;\" ng-show=\"subForm" + repVal + ".r_" + FormF.name +
                             "LongDE.$error.min || subForm" + repVal + ".r_" + FormF.name +
                             "LongDE.$error.max\"><i class=\"fa fa-warning\"></i>Invalid coords!</span>\n";
                filedBody += "\n";
            }
        }
        catch (Exception ex)
        {
            LogUtils.WriteErrorLog(ex.ToString());
        }
    }
    /// <summary>
    /// Creates the HTML structure of the field passed in input.
    /// Each field is created using AngularJS directives.
    /// </summary>
    /// <param name="FormF">FormField to analyze</param>
    private void switchDataEntry(FormFieldExport FormF)
    {
        string filedLabe = "";
        string filedBody = "";
        switch(FormF.type)
        {
            case "DATE_FIELD":
                #region DateField
                if(prevFieldID != 0 && FormF.FormFieldParentID == null)
                {
                    angJSForm.Text += "</div></li></ul></div>\n";
                    if(closeRosterRelevant == 1)
                    {
                        angJSForm.Text += "</div>\n";
                        closeRosterRelevant = 0;
                    }
                }
                outVal = "";
                if(relevant.TryGetValue((int)FormF.id, out outVal))
                {
                    angJSForm.Text += outVal;
                }
                if(FormF.FormFieldParentID == null)
                {
                    ngModelName.Add(FormF.name);
                    filedLabe = FormF.label;
                    filedBody = "<input type=\"text\" ng-model=\"" + model + FormF.name + "\" class=\"col-xs-10 col-sm-8\" ";
                    if(FormF.isReadOnly == 1)
                    {
                        filedBody += " ng-readonly=\"1\" ";
                    }
                    if(FormF.required == 1)
                    {
                        filedBody += " name=\"r_" + FormF.name + "\"";
                        if(outVal != null && outVal != "")
                        {
                            filedBody += " ng-required=\"currForm" + Regex.Match(outVal, "currForm(.+?)\">").Groups[1].Value + " jqdatepicker />\n";
                        }
                        else filedBody += " required jqdatepicker />\n";
                        filedBody += "<span style=\"color: #f1c409; padding: 5px;\" ng-show=\"mainForm.r_" + FormF.name + ".$error.required\"><i class=\"fa fa-warning\"></i></span>\n";
                    }
                    else filedBody += "/>\n";

                }
                else
                {
                    repVal = "";
                    roaster.TryGetValue((int)FormF.FormFieldParentID, out repVal);
                    if(repVal == null)
                        table.TryGetValue((int)FormF.FormFieldParentID, out repVal);
                    filedLabe = FormF.label;

                    filedBody += "<input type=\"text\" ng-model=\"rb_" + repVal + "." + FormF.name + "\" class=\"col-xs-10 col-sm-8\" ";
                    ngModelNameSubForm.Add(FormF.name, "rb_" + repVal + ".");
                    if(FormF.isReadOnly == 1)
                    {
                        filedBody += " ng-readonly=\"1\" ";
                    }
                    if(FormF.required == 1)
                    {
                        filedBody += " name=\"r_" + FormF.name + "\"";
                        if(outVal != null && outVal != "")
                        {
                            filedBody += " ng-required=\"currForm" + Regex.Match(outVal, "currForm(.+?)\">").Groups[1].Value + " jqdatepicker />\n";
                        }
                        else filedBody += " required jqdatepicker />\n";
                        filedBody += "<span style=\"color: #f1c409; padding: 5px;\" ng-show=\"subForm" + repVal + ".r_" + FormF.name + ".$error.required\"><i class=\"fa fa-warning\"></i></span>\n";
                    }
                    else filedBody += "/>\n";

                }
                angJSForm.Text += getFieldBody(filedLabe, filedBody);

                if(outVal != null && outVal != "")
                {
                    angJSForm.Text += "</div>\n";
                }

                prevFieldID = (FormF.FormFieldParentID == null) ? 0 : (int)FormF.FormFieldParentID;
                #endregion
                break;
            case "PHONE_NUMBER_FIELD":
            case "BARCODE":
            case "TEXT_FIELD":
                #region TextField
                if(prevFieldID != 0 && FormF.FormFieldParentID == null)
                {
                    angJSForm.Text += "</div></li></ul></div>\n";
                    if(closeRosterRelevant == 1)
                    {
                        angJSForm.Text += "</div>\n";
                        closeRosterRelevant = 0;
                    }
                }

                outVal = "";
                if(FormF.FormFieldParentID == null)
                {
                    ngModelName.Add(FormF.name);

                    filedLabe = FormF.label;

                    if(relevant.TryGetValue((int)FormF.id, out outVal))
                    {
                        angJSForm.Text += outVal;
                    }

                    filedBody += "<input type=\"text\" ng-model=\"" + model + FormF.name + "\" class=\"col-xs-10 col-sm-8\" ";
                    if(FormF.isReadOnly == 1)
                    {
                        filedBody += " ng-readonly=\"1\" ";
                    }
                    var val = (from v in responseValues
                               where v.formFieldId == FormF.id
                               select v.value).FirstOrDefault();
                    if(val != null)
                    {
                        filedBody += " ng-init=\"" + model + FormF.name + "='" + val + "'\" ";
                    }
                    if(FormF.required == 1)
                    {
                        filedBody += " name=\"r_" + FormF.name + "\"";
                        if(outVal != null && outVal != "")
                        {
                            filedBody += " ng-required=\"currForm" + Regex.Match(outVal, "currForm(.+?)\">").Groups[1].Value + "\" />\n";
                        }
                        else
                        {
                            filedBody += " required />\n";
                        }
                        filedBody += "<span style=\"color: #f1c409; padding: 5px;\" ng-show=\"mainForm.r_" + FormF.name + ".$error.required\"><i class=\"fa fa-warning\"></i></span>\n";
                    }
                    else
                    {
                        filedBody += "/>\n";
                    }
                }
                else
                {
                    repVal = "";
                    roaster.TryGetValue((int)FormF.FormFieldParentID, out repVal);
                    if(repVal == null)
                        table.TryGetValue((int)FormF.FormFieldParentID, out repVal);

                    filedLabe = FormF.label;

                    if(relevant.TryGetValue((int)FormF.id, out outVal))
                    {
                        angJSForm.Text += outVal.Replace("currForm", "rb_" + repVal);
                    }

                    filedBody += "  <input type=\"text\" ng-model=\"rb_" + repVal + "." + FormF.name + "\"  class=\"col-xs-10 col-sm-8\" ";
                    ngModelNameSubForm.Add(FormF.name, "rb_" + repVal + ".");
                    if(FormF.isReadOnly == 1)
                    {
                        filedBody += " ng-readonly=\"1\" ";
                    }
                    if(FormF.required == 1)
                    {
                        filedBody += " name=\"r_" + FormF.name + "\"";
                        if(outVal != null && outVal != "")
                        {
                            filedBody += " ng-required=\"rb_" + Regex.Match(outVal, "currForm(.+?)\">").Groups[1].Value + "\" />\n";
                        }
                        else
                        {
                            filedBody += " required />\n";
                        }
                        filedBody += "<span style=\"color: #f1c409; padding: 5px;\" ng-show=\"subForm" + repVal + ".r_" + FormF.name + ".$error.required\"><i class=\"fa fa-warning\"></i></span>\n";
                    }
                    else
                    {
                        filedBody += "/>\n";
                    }

                }
                angJSForm.Text += getFieldBody(filedLabe, filedBody);

                if(outVal != null && outVal != "")
                {
                    angJSForm.Text += "</div>\n";
                }

                prevFieldID = (FormF.FormFieldParentID == null) ? 0 : (int)FormF.FormFieldParentID;
                #endregion
                break;
            case "TEXT_AREA":
                #region TextArea
                if(prevFieldID != 0 && FormF.FormFieldParentID == null)
                {
                    angJSForm.Text += "</div></li></ul></div>\n";
                    if(closeRosterRelevant == 1)
                    {
                        angJSForm.Text += "</div>\n";
                        closeRosterRelevant = 0;
                    }
                }
                outVal = "";
                if(relevant.TryGetValue((int)FormF.id, out outVal))
                {
                    angJSForm.Text += outVal;
                }
                if(FormF.FormFieldParentID == null)
                {
                    ngModelName.Add(FormF.name);

                    filedLabe = FormF.label;
                    filedBody += "<textarea rows=\"2\" ng-model=\"" + model + FormF.name + "\" class=\"col-xs-10 col-sm-8\" ";
                    if(FormF.isReadOnly == 1)
                    {
                        filedBody += " ng-readonly=\"1\" ";
                    }
                    if(FormF.required == 1)
                    {
                        filedBody += " name=\"r_" + FormF.name + "\"";
                        if(outVal != null && outVal != "")
                        {
                            filedBody += " ng-required=\"currForm" + Regex.Match(outVal, "currForm(.+?)\">").Groups[1].Value + "\" ></textarea>\r\n";
                        }
                        else
                        {
                            filedBody += " required ></textarea>\r\n";
                        }
                        filedBody += "<span style=\"color: #f1c409; padding: 5px;\" ng-show=\"mainForm.r_" + FormF.name + ".$error.required\"><i class=\"fa fa-warning\"></i></span> \r\n";
                    }
                    else filedBody += "></textarea> \r\n";
                }
                else
                {
                    repVal = "";
                    roaster.TryGetValue((int)FormF.FormFieldParentID, out repVal);
                    if(repVal == null)
                        table.TryGetValue((int)FormF.FormFieldParentID, out repVal);

                    filedLabe = FormF.label;
                    filedBody += "<textarea rows=\"2\" ng-model=\"rb_" + repVal + "." + FormF.name + "\"  class=\"col-xs-10 col-sm-8\"";
                    ngModelNameSubForm.Add(FormF.name, "rb_" + repVal + ".");
                    if(FormF.isReadOnly == 1)
                    {
                        filedBody += " ng-readonly=\"1\" ";
                    }
                    if(FormF.required == 1)
                    {
                        filedBody += " name=\"r_" + FormF.name + "\"";
                        if(outVal != null && outVal != "")
                        {
                            filedBody += " ng-required=\"currForm" + Regex.Match(outVal, "currForm(.+?)\">").Groups[1].Value + "\" ></textarea>\n";
                        }
                        else filedBody += " required ></textarea>\n";
                        filedBody += "<span style=\"color: #f1c409; padding: 5px;\" ng-show=\"subForm" + repVal + ".r_" + FormF.name + ".$error.required\"><i class=\"fa fa-warning\"></i></span> </div>\n";
                    }
                    else filedBody += "></textarea> </div>\n";

                }

                angJSForm.Text += getFieldBody(filedLabe, filedBody);
                if(outVal != null && outVal != "")
                {
                    angJSForm.Text += "</div>\n";
                }

                prevFieldID = (FormF.FormFieldParentID == null) ? 0 : (int)FormF.FormFieldParentID;
                #endregion
                break;
            case "CURRENCY_FIELD":
            case "NUMERIC_TEXT_FIELD":
                #region NumericField
                if(prevFieldID != 0 && FormF.FormFieldParentID == null)
                {
                    angJSForm.Text += "</div></li></ul></div>\n";
                    if(closeRosterRelevant == 1)
                    {
                        angJSForm.Text += "</div>\n";
                        closeRosterRelevant = 0;
                    }
                }
                outVal = "";
                if(relevant.TryGetValue((int)FormF.id, out outVal))
                {
                    angJSForm.Text += outVal;
                }
                if(FormF.FormFieldParentID == null)
                {
                    filedLabe = FormF.label;
                    ngModelName.Add(FormF.name);
                    filedBody += "<input type=\"number\" ng-model=\"" + model + FormF.name + "\" class=\"col-xs-10 col-sm-8\" ";
                    if(FormF.isReadOnly == 1 || FormF.calculated == 1)
                    {
                        filedBody += " ng-readonly=\"1\" ";
                    }
                    var val = (from v in responseValues
                               where v.formFieldId == FormF.id
                               select v.value).FirstOrDefault();
                    if(val != null && val.Length > 0)
                    {
                        filedBody += " ng-init=\"" + model + FormF.name + "=" + val.Replace(".0", "") + "\" ";
                    }
                    constr = "";
                    List<FieldConstraintRel> currFieldConstraints = (from fc in fieldConstraintRel
                                                                     where fc.FormFieldID == (int)FormF.id
                                                                     select fc).ToList();
                    foreach(FieldConstraintRel fcr in currFieldConstraints)
                    {
                        if(constraint.TryGetValue(fcr.ConstraintID, out constr))
                        {
                            filedBody += constr;
                        }
                    }
                    if(FormF.required == 1)
                    {
                        filedBody += " name=\"r_" + FormF.name + "\"";
                        //constr = "";
                        //if (constraint.TryGetValue((int)FormF.id, out constr))
                        //{
                        //    angJSForm.Text += constr;
                        //}
                        if(outVal != null && outVal != "")
                        {
                            ltlScript.Text += "$scope." + model + FormF.name + " = 0;";
                            filedBody += " ng-required=\"currForm" + Regex.Match(outVal, "currForm(.+?)\">").Groups[1].Value + "\" />\n";
                        }
                        else filedBody += " required />\n";
                        if(constr != null && constr != "")
                        {
                            filedBody += "<span ng-show=\"mainForm.r_" + FormF.name + ".$error.min || mainForm.r_" + FormF.name + ".$error.max\">Out of Bounds!</span>\n";
                        }
                        filedBody += "<span style=\"color: #f1c409; padding: 5px;\" ng-show=\"mainForm.r_" + FormF.name + ".$error.required\"><i class=\"fa fa-warning\"></i></span>";
                        filedBody += "<span style=\"color: red; padding: 5px;\" ng-show=\"mainForm.r_" + FormF.name + ".$error.number\"><i class=\"fa fa-warning\"></i></span>\n";
                    }
                    else if(constr != null && constr != "")
                    {
                        filedBody += " name=\"r_" + FormF.name + "\"";
                        filedBody += "/>\n<span ng-show=\"mainForm.r_" + FormF.name + ".$error.min || mainForm.r_" + FormF.name + ".$error.max\">Out of Bounds!</span>\n";
                    }
                    else filedBody += "/>\n";
                    if(FormF.calculated == 1)
                    {
                        if(FormF.formula != null)
                        {
                            bool isInModel = false;
                            foreach(string i in ngModelName)
                            {
                                if(FormF.formula.Contains(i))
                                {
                                    isInModel = true;
                                }
                            }
                            if(isInModel)
                            {
                                ltlScript.Text += "$scope.$watch('" + getFormula(FormF.formula) + "', function (value) {  $scope." + model + FormF.name + "= value;}, true);";
                            }
                            else
                            {
                                ltlScript.Text += getFormula(FormF.formula, "$scope." + model + FormF.name, repVal);
                            }
                        }
                    }
                }
                else
                {
                    repVal = "";
                    roaster.TryGetValue((int)FormF.FormFieldParentID, out repVal);
                    if(repVal == null)
                        table.TryGetValue((int)FormF.FormFieldParentID, out repVal);
                    filedLabe = FormF.label;
                    filedBody += "<input type=\"number\" ng-model=\"rb_" + repVal + "." + FormF.name + "\" class=\"col-xs-10 col-sm-8\" ";
                    ngModelNameSubForm.Add(FormF.name, "rb_" + repVal + ".");
                    ngModelCalculatedOutofModel.Add(FormF.name, "currForm." + repVal);
                    if(FormF.isReadOnly == 1 || FormF.calculated == 1)
                    {
                        filedBody += " ng-readonly=\"1\" ";
                    }
                    constr = "";
                    if(constraint.TryGetValue((int)FormF.id, out constr))
                    {
                        filedBody += constr;
                    }
                    if(FormF.required == 1)
                    {
                        filedBody += " name=\"r_" + FormF.name + "\"";
                        //constr = "";
                        //if (constraint.TryGetValue((int)FormF.id, out constr))
                        //{
                        //    angJSForm.Text += constr;
                        //}
                        if(outVal != null && outVal != "")
                        {
                            filedBody += " ng-required=\"currForm" + Regex.Match(outVal, "currForm(.+?)\">").Groups[1].Value + "\" />\n";
                        }
                        else filedBody += " required />\n";
                        if(constr != null && constr != "")
                        {
                            filedBody += "<span ng-show=\"subForm" + repVal + ".r_" + FormF.name + ".$error.min || subForm" + repVal + ".r_" + FormF.name + ".$error.max\">Out of Bounds!</span>\n";
                        }
                        filedBody += "<span style=\"color: #f1c409; padding: 5px;\" ng-show=\"subForm" + repVal + ".r_" + FormF.name + ".$error.required\"><i class=\"fa fa-warning\"></i></span>";
                        filedBody += "<span style=\"color: red; padding: 5px;\" ng-show=\"subForm" + repVal + ".r_" + FormF.name + ".$error.number\"><i class=\"fa fa-warning\"></i></span>\n";
                    }
                    else if(constr != null && constr != "")
                    {
                        filedBody += " name=\"r_" + FormF.name + "\"";
                        filedBody += "/>\n<span ng-show=\"subForm" + repVal + ".r_" + FormF.name + ".$error.min || subForm" + repVal + ".r_" + FormF.name + ".$error.max\">Out of Bounds!</span>\n";
                    }
                    else filedBody += "/>\n";
                    if(FormF.calculated == 1)
                    {
                        if(FormF.formula != null)
                        {
                            ltlScript.Text += "$scope.$watch('currForm." + repVal + "', function (value) { var i = 0;for(i = 0; i < value.length; i++) value[i]." + FormF.name + " = " + getFormula(FormF.formula, repVal) + ";}, true);";
                        }
                    }
                }
                angJSForm.Text += getFieldBody(filedLabe, filedBody);
                if(outVal != null && outVal != "")
                {
                    angJSForm.Text += "</div>\n";
                }

                prevFieldID = (FormF.FormFieldParentID == null) ? 0 : (int)FormF.FormFieldParentID;
                #endregion
                break;
            case "DROP_DOWN_LIST":
                #region DropDownList
                if(prevFieldID != 0 && FormF.FormFieldParentID == null)
                {
                    angJSForm.Text += "</div></li></ul></div>\n";
                    if(closeRosterRelevant == 1)
                    {
                        angJSForm.Text += "</div>\n";
                        closeRosterRelevant = 0;
                    }
                }
                if(!ltlScript.Text.Contains("$scope.options" + (int)FormF.survey_id + "="))
                {
                    script = "";
                    script += "$scope.options" + (int)FormF.survey_id + "= [";
                    foreach(SurveyElement se in getOptions((int)FormF.survey_id))
                    {
                        script += "{value:\"" + se.value.Replace("'", @"\\'").Replace("\r\n", " ").Replace("\n", " ") + "\"},";
                    }
                    ltlScript.Text += script.Substring(0, script.Length - 1);
                    ltlScript.Text += "];";
                }

                outVal = "";
                if(relevant.TryGetValue((int)FormF.id, out outVal))
                {
                    angJSForm.Text += outVal;
                }
                filedLabe = FormF.label;
                if(FormF.FormFieldParentID == null)
                {
                    ngModelName.Add(FormF.name);

                    filedBody += "<select ng-model=\"" + model + FormF.name + ".value\" class=\"col-xs-10 col-sm-8\" ng-options=\"o.value as o.value for o in options" + (int)FormF.survey_id + "\"";
                    //var val = (from v in responseValues
                    //           where v.formFieldId == FormF.id
                    //           select v.value).FirstOrDefault();
                    //if(val != null)
                    //{
                    //    filedBody += " ng-init=\"" + model + FormF.name + "=options" + (int)FormF.survey_id + "[3]\" ";
                    //}
                    if(FormF.required == 1)
                    {
                        filedBody += " name=\"r_" + FormF.name + "\"";
                        if(outVal != null && outVal != "")
                        {
                            filedBody += " ng-required=\"currForm" + Regex.Match(outVal, "currForm(.+?)\">").Groups[1].Value + "\" ></select>\n";
                        }
                        else filedBody += " required ></select>";
                        filedBody += "<span style=\"color: #f1c409; padding: 5px;\" ng-show=\"mainForm.r_" + FormF.name + ".$error.required\"><i class=\"fa fa-warning\"></i></span>\n";
                    }
                    else filedBody += "></select>\n";
                }
                else
                {
                    repVal = "";
                    roaster.TryGetValue((int)FormF.FormFieldParentID, out repVal);
                    if(repVal == null)
                        table.TryGetValue((int)FormF.FormFieldParentID, out repVal);
                    filedBody += "<select ng-model=\"rb_" + repVal + "." + FormF.name + ".value\" class=\"col-xs-10 col-sm-8\" ng-options=\"o.value as o.value for o in options" + (int)FormF.survey_id + "\"";

                    if(!ngModelNameSubForm.ContainsKey(FormF.name))
                        ngModelNameSubForm.Add(FormF.name, "rb_" + repVal + ".");
                    if(FormF.required == 1)
                    {
                        filedBody += " name=\"r_" + FormF.name + "\"";
                        if(outVal != null && outVal != "")
                        {
                            filedBody += " ng-required=\"currForm" + Regex.Match(outVal, "currForm(.+?)\">").Groups[1].Value + "\" /></select>\n";
                        }
                        else filedBody += " required /></select>\n";
                        filedBody += "<span style=\"color: #f1c409; padding: 5px;\" ng-show=\"subForm" + repVal + ".r_" + FormF.name + ".$error.required\"><i class=\"fa fa-warning\"></i></span>\n";
                    }
                    else filedBody += "/></select>\n";
                }

                angJSForm.Text += getFieldBody(filedLabe, filedBody);
                if(outVal != null && outVal != "")
                {
                    angJSForm.Text += "</div>\n";
                }

                prevFieldID = (FormF.FormFieldParentID == null) ? 0 : (int)FormF.FormFieldParentID;
                #endregion
                break;
            case "RADIO_BUTTON":
                #region RadioButton
                if(prevFieldID != 0 && FormF.FormFieldParentID == null)
                {
                    angJSForm.Text += "</div></li></ul></div>\n";
                    if(closeRosterRelevant == 1)
                    {
                        angJSForm.Text += "</div>\n";
                        closeRosterRelevant = 0;
                    }
                }
                outVal = "";
                if(relevant.TryGetValue((int)FormF.id, out outVal))
                {
                    angJSForm.Text += outVal;
                }
                filedLabe = FormF.label;

                foreach(SurveyElement se in getOptions((int)FormF.survey_id))
                {

                    if(FormF.FormFieldParentID == null)
                    {
                        ngModelName.Add(FormF.name);

                        filedBody += "<label class=\"inline\"><input type=\"radio\" class=\"ace\"  ng-model=\"" + model + FormF.name + "\" value=\"" + se.value + "\"";

                        var val = (from v in responseValues
                                   where v.formFieldId == FormF.id
                                   select v.value).FirstOrDefault();
                        if(val != null)
                        {
                            filedBody += " ng-init=\"" + model + FormF.name + "='" + val + "'\" ";
                        }

                        if(FormF.required == 1)
                        {
                            filedBody += " name=\"r_" + FormF.name + "\"";
                            if(outVal != null && outVal != "")
                            {
                                filedBody += " ng-required=\"currForm" + Regex.Match(outVal, "currForm(.+?)\">").Groups[1].Value + "\" />\n";
                                filedBody += "<span class=\"lbl\"> " + se.value + "</span></label> \n";
                            }
                            else
                            {
                                filedBody += " required ><span class=\"lbl\"> " + se.value + "</span></label>\n";
                            }
                            //  angJSForm.Text += "<span style=\"color: #f1c409; padding: 5px;\" ng-show=\"mainForm.r_" + FormF.name + ".$error.required\"><i class=\"fa fa-warning\"></i></span></div>\n";
                        }
                        else
                        {
                            filedBody += " ><span class=\"lbl\"> " + se.value + "</span></label>\n";
                        }

                        //angJSForm.Text += "<div class=\"right\"><label>" + se.value + "</label><input type=\"radio\" ng-model=\"" + model + FormF.name + "\" value=\"" + se.value + "\"";
                        //if (FormF.required == 1)
                        //{
                        //    angJSForm.Text += " name=\"r_" + FormF.name + "\"";
                        //    if (outVal != null && outVal != "")
                        //    {
                        //        angJSForm.Text += " ng-required=\"currForm" + Regex.Match(outVal, "currForm(.+?)\">").Groups[1].Value + "\" />\n";
                        //    }
                        //    else angJSForm.Text += " required />\n";
                        //    angJSForm.Text += "<span style=\"color: #f1c409; padding: 5px;\" ng-show=\"mainForm.r_" + FormF.name + ".$error.required\"><i class=\"fa fa-warning\"></i></span></div>\n";
                        //}
                        //else angJSForm.Text += "/></div>\n";
                    }
                    else
                    {
                        //repVal = "";
                        //roaster.TryGetValue((int)FormF.FormFieldParentID, out repVal);
                        //if (repVal == null)
                        //    table.TryGetValue((int)FormF.FormFieldParentID, out repVal);
                        //angJSForm.Text += "<div class=\"left clear\"><label>" + se.value + "</label></div><div class=\"right\"><input type=\"radio\" ng-model=\"rb_" + repVal + "." + FormF.name + "\" value=\"" + se.value + "\"";
                        //if (!ngModelNameSubForm.ContainsKey(FormF.name))
                        //    ngModelNameSubForm.Add(FormF.name, "rb_" + repVal + ".");
                        //if (FormF.required == 1)
                        //{
                        //    angJSForm.Text += " name=\"r_{{$index}}" + FormF.name + "\"";
                        //    if (outVal != null && outVal != "")
                        //    {
                        //        angJSForm.Text += " ng-required=\"currForm" + Regex.Match(outVal, "currForm(.+?)\">").Groups[1].Value + "\" />\n";
                        //    }
                        //    else angJSForm.Text += " required />\n";
                        //    angJSForm.Text += "<span style=\"color: #f1c409; padding: 5px;\" ng-show=\"subForm" + repVal + ".r_" + FormF.name + ".$error.required\"><i class=\"fa fa-warning\"></i></span></div>\n";
                        //}
                        //else angJSForm.Text += "/></div>\n";

                        repVal = "";
                        roaster.TryGetValue((int)FormF.FormFieldParentID, out repVal);

                        if(repVal == null)
                            table.TryGetValue((int)FormF.FormFieldParentID, out repVal);

                        filedBody += "<label class=\"inline\"><input type=\"radio\" class=\"ace\"  ng-model=\"rb_" + repVal + "." + FormF.name + "\" value=\"" + se.value + "\"";

                        if(!ngModelNameSubForm.ContainsKey(FormF.name))
                            ngModelNameSubForm.Add(FormF.name, "rb_" + repVal + ".");
                        if(FormF.required == 1)
                        {
                            filedBody += " name=\"r_{{$index}}" + FormF.name + "\"";
                            if(outVal != null && outVal != "")
                            {
                                filedBody += " ng-required=\"currForm" + Regex.Match(outVal, "currForm(.+?)\">").Groups[1].Value + "\" />\n";
                                filedBody += "<span class=\"lbl\"> " + se.value + "</span></label> \n";
                            }
                            else
                            {
                                filedBody += " required ><span class=\"lbl\"> " + se.value + "</span></label>\n";
                            }

                        }
                        else
                        {
                            filedBody += " ><span class=\"lbl\"> " + se.value + "</span></label> \n";
                        }

                    }
                }
                if(FormF.FormFieldParentID == null)
                {
                    filedBody += "<span style=\"color: #f1c409; padding: 5px;\" ng-show=\"mainForm.r_" + FormF.name + ".$error.required\"><i class=\"fa fa-warning\"></i></span> \n";
                }
                else
                {

                    filedBody += "<span style=\"color: #f1c409; padding: 5px;\" ng-show=\"subForm" + repVal + ".r_" + FormF.name + ".$error.required\"><i class=\"fa fa-warning\"></i></span> \n";

                }
                if(outVal != null && outVal != "")
                {
                    filedBody += "</div>\n";
                }
                angJSForm.Text += getFieldBody(filedLabe, filedBody);

                prevFieldID = (FormF.FormFieldParentID == null) ? 0 : (int)FormF.FormFieldParentID;
                #endregion
                break;
            case "CHECK_BOX":
                #region Checkbox
                if(prevFieldID != 0 && FormF.FormFieldParentID == null)
                {
                    angJSForm.Text += "</div></li></ul></div>\n";
                    if(closeRosterRelevant == 1)
                    {
                        angJSForm.Text += "</div>\n";
                        closeRosterRelevant = 0;
                    }
                }
                outVal = "";
                if(relevant.TryGetValue((int)FormF.id, out outVal))
                {
                    filedBody += outVal;
                }
                if(FormF.FormFieldParentID == null)
                {
                    filedLabe = FormF.label;

                    ngModelName.Add(FormF.name);
                    ltlScript.Text += "$scope." + model + FormF.name + " = false;";

                    filedBody += "<input type=\"checkbox\" ng-model=\"" + model + FormF.name + "\"";
                    if(FormF.isReadOnly == 1 || FormF.calculated == 1)
                    {
                        filedBody += " ng-readonly=\"1\" ";
                    }
                    constr = "";
                    if(constraint.TryGetValue((int)FormF.id, out constr))
                    {
                        filedBody += constr;
                    }
                    if(FormF.required == 1)
                    {
                        filedBody += " name=\"r_" + FormF.name + "\"";
                        //constr = "";
                        //if (constraint.TryGetValue((int)FormF.id, out constr))
                        //{
                        //    angJSForm.Text += constr;
                        //}
                        if(outVal != null && outVal != "")
                        {
                            filedBody += " ng-required=\"currForm" + Regex.Match(outVal, "currForm(.+?)\">").Groups[1].Value + "\" />\n";
                        }
                        else filedBody += " required />\n";
                        filedBody += "<span style=\"color: #f1c409; padding: 5px;\" ng-show=\"mainForm.r_" + FormF.name + ".$error.required\"><i class=\"fa fa-warning\"></i></span>\n";
                    }
                    else filedBody += "/>\n";
                }
                else
                {
                    repVal = "";
                    filedLabe = FormF.label;
                    roaster.TryGetValue((int)FormF.FormFieldParentID, out repVal);
                    if(repVal == null)
                        table.TryGetValue((int)FormF.FormFieldParentID, out repVal);
                    filedBody += "<input type=\"checkbox\" ng-model=\"rb_" + repVal + "." + FormF.name + "\"";
                    ngModelNameSubForm.Add(FormF.name, "rb_" + repVal + ".");
                    if(FormF.isReadOnly == 1 || FormF.calculated == 1)
                    {
                        filedBody += " ng-readonly=\"1\" ";
                    }
                    constr = "";
                    if(constraint.TryGetValue((int)FormF.id, out constr))
                    {
                        filedBody += constr;
                    }
                    if(FormF.required == 1)
                    {
                        filedBody += " name=\"r_" + FormF.name + "\"";
                        //constr = "";
                        //if (constraint.TryGetValue((int)FormF.id, out constr))
                        //{
                        //    angJSForm.Text += constr;
                        //}
                        if(outVal != null && outVal != "")
                        {
                            filedBody += " ng-required=\"currForm" + Regex.Match(outVal, "currForm(.+?)\">").Groups[1].Value + "\" />\n";
                        }
                        else filedBody += " required />\n";
                        filedBody += "<span style=\"color: #f1c409; padding: 5px;\" ng-show=\"subForm" + repVal + ".r_" + FormF.name + ".$error.required\"><i class=\"fa fa-warning\"></i></span>\n";
                    }
                    else filedBody += "/>\n";
                }
                angJSForm.Text += getFieldBody(filedLabe, filedBody);
                if(outVal != null && outVal != "")
                {
                    angJSForm.Text += "</div>\n";
                }
                prevFieldID = (FormF.FormFieldParentID == null) ? 0 : (int)FormF.FormFieldParentID;
                #endregion
                break;
            case "REPEATABLES_BASIC":
                #region RepeatableBasic
                if(prevFieldID != 0 && FormF.FormFieldParentID == null)
                {
                    angJSForm.Text += "</div></li></ul></div>\n";
                    if(closeRosterRelevant == 1)
                    {
                        angJSForm.Text += "</div>\n";
                        closeRosterRelevant = 0;
                    }
                }
                outVal = "";
                closeRosterRelevant = 0;
                if(relevant.TryGetValue((int)FormF.id, out outVal))
                {
                    angJSForm.Text += outVal;
                    closeRosterRelevant = 1;
                }

                ltlScript.Text += "$scope." + model + FormF.name + " = [];";
                checkFieldForRoaster((int)FormF.id, FormF.name);
                roaster.Add((int)FormF.id, FormF.name);
                angJSForm.Text += "<div class=\"col-sm-9 form-group\"><label>Roster " + FormF.label + "</label><br/>\n";
                angJSForm.Text += "<a ng-click=\"addNew" + FormF.name + "()\"><i class=\"fa fa-plus\"></i> Add New " + FormF.name + "</a></div><div class=\"col-sm-11 form-group\"><ul>";
                angJSForm.Text += "<li ng-repeat=\"rb_" + FormF.name + " in " + model + FormF.name + "\" ng-form=\"subForm" + FormF.name + "\">\n<div style=\"overflow: hidden;\">";
                prevFieldID = (FormF.FormFieldParentID == null) ? 0 : (int)FormF.FormFieldParentID;
                #endregion
                break;
            case "REPEATABLES":
                #region Repeatable
                if(prevFieldID != 0 && FormF.FormFieldParentID == null)
                {
                    angJSForm.Text += "</div></li></ul></div>\n";
                    if(closeRosterRelevant == 1)
                    {
                        angJSForm.Text += "</div>\n";
                        closeRosterRelevant = 0;
                    }
                }
                outVal = "";
                closeRosterRelevant = 0;
                if(relevant.TryGetValue((int)FormF.id, out outVal))
                {
                    angJSForm.Text += outVal;
                    closeRosterRelevant = 1;
                }
                prevFieldID = (FormF.FormFieldParentID == null) ? 0 : (int)FormF.FormFieldParentID;
                ltlScript.Text += "$scope." + model + FormF.name + " = [";
                checkFieldForTable((int)FormF.survey_id);
                table.Add((int)FormF.id, FormF.name);
                angJSForm.Text += "<div class=\"col-sm-9 form-group\"><label>" + FormF.label + "</label><br/>\n";
                //<label class=\"col-sm-3 control-label no-padding-right\">" + FormF.label + "</label>\n
                angJSForm.Text += "<div class=\"col-sm-9 form-group\"><ul><li ng-repeat=\"rb_" + FormF.name + " in " + model + FormF.name + "\" ng-form=\"subForm" + FormF.name + "\">\n<div style=\"overflow: hidden;\">";
                angJSForm.Text += "<label>{{rb_" + FormF.name + ".value}}</label><br />";
                #endregion
                break;
            case "SEPARATOR":
                if(prevFieldID != 0 && FormF.FormFieldParentID == null)
                {
                    angJSForm.Text += "</div></li></ul></div>\n";
                    if(closeRosterRelevant == 1)
                    {
                        angJSForm.Text += "</div>\n";
                        closeRosterRelevant = 0;
                    }
                }
                angJSForm.Text += "<div class=\"clear\"><hr /></div>\n";
                prevFieldID = (FormF.FormFieldParentID == null) ? 0 : (int)FormF.FormFieldParentID;
                break;
            case "TRUNCATED_TEXT":
            case "WRAPPED_TEXT":

                #region WrappedText
                if(prevFieldID != 0 && FormF.FormFieldParentID == null)
                {
                    angJSForm.Text += "</div></li></ul></div>\n";
                    if(closeRosterRelevant == 1)
                    {
                        angJSForm.Text += "</div>\n";
                        closeRosterRelevant = 0;
                    }
                }
                outVal = "";
                if(relevant.TryGetValue((int)FormF.id, out outVal))
                {
                    angJSForm.Text += outVal;
                }
                if(FormF.FormFieldParentID == null)
                {
                    angJSForm.Text += "<div class=\"col-sm-9 form-group\"><label style=\"font-weight: bold;\" ng-model=\"" + model + FormF.name + "\">" + FormF.label + "</label></div>\n";
                }
                else
                {
                    repVal = "";
                    roaster.TryGetValue((int)FormF.FormFieldParentID, out repVal);
                    if(repVal == null)
                        table.TryGetValue((int)FormF.FormFieldParentID, out repVal);
                    angJSForm.Text += "<div class=\"col-sm-9 form-group\"><label style=\"font-weight: bold;\" ng-model=\"rb_" + repVal + "." + FormF.name + "\">" + FormF.label + "</label></div>\n";
                }

                if(outVal != null && outVal != "")
                {
                    angJSForm.Text += "</div>\n";
                }
                prevFieldID = (FormF.FormFieldParentID == null) ? 0 : (int)FormF.FormFieldParentID;
                #endregion
                break;
            case "GEOLOCATION":
                //GeoLocation cannot be edited, so it's replaced w a simple disabled TEXTFIELD
                #region Geolocation
                if(prevFieldID != 0 && FormF.FormFieldParentID == null)
                {
                    angJSForm.Text += "</div></li></ul></div>\n";
                    if(closeRosterRelevant == 1)
                    {
                        angJSForm.Text += "</div>\n";
                        closeRosterRelevant = 0;
                    }
                }

                outVal = "";
                if(relevant.TryGetValue((int)FormF.id, out outVal))
                {
                    angJSForm.Text += outVal;
                }

                FormHTMLUtils.WriteGPSHTMLField(FormF, true, responseValues, ref filedLabe,
                    ngModelName,
                    ref filedBody,
                    ref constr,
                    constraint,
                    ref outVal,
                    ltlScript,
                    ref repVal,
                    roaster,
                    table,
                    ngModelNameSubForm,
                    ref model);

                //s* remove this old code
                //if(FormF.FormFieldParentID == null)
                //{
                //    ngModelName.Add(FormF.name);

                //    filedLabe = FormF.label;
                //    filedBody += "<input type=\"text\" ng-model=\"" + model + FormF.name + "\" class=\"col-xs-10 col-sm-8\" "; //disabled=\"disabled\"
                //    if(FormF.isReadOnly == 1)//-
                //    {
                //        filedBody += " ng-readonly=\"1\" ";
                //    }
                //    var val = (from v in responseValues
                //               where v.formFieldId == FormF.id
                //               select v.value).FirstOrDefault(); //-
                //    if(val != null) //-
                //    {
                //        filedBody += " ng-init=\"" + model + FormF.name + "='" + val + "'\" ";
                //    }
                //    if(FormF.required == 1)
                //    {
                //        filedBody += " name=\"r_" + FormF.name + "\"";
                //        if(outVal != null && outVal != "")
                //        {
                //            filedBody += " ng-required=\"currForm" + Regex.Match(outVal, "currForm(.+?)\">").Groups[1].Value + "\" />\n";
                //        }
                //        else filedBody += " required />\n";
                //        filedBody += "<span style=\"color: #f1c409; padding: 5px;\" ng-show=\"mainForm.r_" + FormF.name + ".$error.required\"><i class=\"fa fa-warning\"></i></span>\n";
                //    }
                //    else filedBody += "/>\n";
                //}
                //else
                //{
                //    repVal = "";
                //    roaster.TryGetValue((int)FormF.FormFieldParentID, out repVal);
                //    if(repVal == null)
                //        table.TryGetValue((int)FormF.FormFieldParentID, out repVal);

                //    filedLabe = FormF.label;
                //    filedBody += "  <input  type=\"text\" ng-model=\"rb_" + repVal + "." + FormF.name + "\"  class=\"col-xs-10 col-sm-8\" "; //disabled=\"disabled\"
                //    ngModelNameSubForm.Add(FormF.name, "rb_" + repVal + ".");
                //    if(FormF.isReadOnly == 1)
                //    {
                //        filedBody += " ng-readonly=\"1\" ";
                //    }
                //    if(FormF.required == 1)
                //    {
                //        filedBody += " name=\"r_" + FormF.name + "\"";
                //        if(outVal != null && outVal != "")
                //        {
                //            filedBody += " ng-required=\"currForm" + Regex.Match(outVal, "currForm(.+?)\">").Groups[1].Value + "\" />\n";
                //        }
                //        else filedBody += " required />\n";
                //        filedBody += "<span style=\"color: #f1c409; padding: 5px;\" ng-show=\"subForm" + repVal + ".r_" + FormF.name + ".$error.required\"><i class=\"fa fa-warning\"></i></span>\n";
                //    }
                //    else filedBody += "/>\n";

                //}
                angJSForm.Text += getFieldBody(filedLabe, filedBody);

                if(outVal != null && outVal != "")
                {
                    angJSForm.Text += "</div>\n";
                }

                prevFieldID = (FormF.FormFieldParentID == null) ? 0 : (int)FormF.FormFieldParentID;
                #endregion
                break;

            case "EMAIL_FIELD":
                #region EmailField
                if(prevFieldID != 0 && FormF.FormFieldParentID == null)
                {
                    angJSForm.Text += "</div></li></ul></div>\n";
                    if(closeRosterRelevant == 1)
                    {
                        angJSForm.Text += "</div>\n";
                        closeRosterRelevant = 0;
                    }
                }
                outVal = "";
                if(relevant.TryGetValue((int)FormF.id, out outVal))
                {
                    angJSForm.Text += outVal;
                }
                if(FormF.FormFieldParentID == null)
                {

                    filedLabe = FormF.label;
                    ngModelName.Add(FormF.name);
                    filedBody += "<input type=\"email\" ng-model=\"" + model + FormF.name + "\" class=\"col-xs-10 col-sm-8\" ";
                    if(FormF.isReadOnly == 1)
                    {
                        filedBody += " ng-readonly=\"1\" ";
                    }
                    if(FormF.required == 1)
                    {
                        filedBody += " name=\"r_" + FormF.name + "\"";
                        if(outVal != null && outVal != "")
                        {
                            filedBody += " ng-required=\"currForm" + Regex.Match(outVal, "currForm(.+?)\">").Groups[1].Value + "\" />\n";
                        }
                        else filedBody += " required />\n";
                        filedBody += "<span style=\"color: #f1c409; padding: 5px;\" ng-show=\"mainForm.r_" + FormF.name + ".$error.required\"><i class=\"fa fa-warning\"></i></span>\n";
                    }
                    else filedBody += "/>\n";
                }
                else
                {
                    repVal = "";
                    roaster.TryGetValue((int)FormF.FormFieldParentID, out repVal);
                    if(repVal == null)
                        table.TryGetValue((int)FormF.FormFieldParentID, out repVal);

                    filedLabe = FormF.label;
                    filedBody += "<input type=\"email\" ng-model=\"rb_" + repVal + "." + FormF.name + "\"";
                    ngModelNameSubForm.Add(FormF.name, "rb_" + repVal + ".");
                    if(FormF.isReadOnly == 1)
                    {
                        filedBody += " ng-readonly=\"1\" ";
                    }
                    if(FormF.required == 1)
                    {
                        filedBody += " name=\"r_" + FormF.name + "\"";
                        if(outVal != null && outVal != "")
                        {
                            filedBody += " ng-required=\"currForm" + Regex.Match(outVal, "currForm(.+?)\">").Groups[1].Value + "\" />\n";
                        }
                        else filedBody += " required />\n";
                        filedBody += "<span style=\"color: #f1c409; padding: 5px;\" ng-show=\"subForm" + repVal + ".r_" + FormF.name + ".$error.required\"><i class=\"fa fa-warning\"></i></span>\n";
                    }
                    else filedBody += "/> \n";
                }
                angJSForm.Text += getFieldBody(filedLabe, filedBody);
                if(outVal != null && outVal != "")
                {
                    angJSForm.Text += "</div>\n";
                }

                prevFieldID = (FormF.FormFieldParentID == null) ? 0 : (int)FormF.FormFieldParentID;
                #endregion
                break;
            case "IMAGE":
                #region Image
                if(prevFieldID != 0 && FormF.FormFieldParentID == null)
                {
                    angJSForm.Text += "</div></li></ul></div>\n";
                    if(closeRosterRelevant == 1)
                    {
                        angJSForm.Text += "</div>\n";
                        closeRosterRelevant = 0;
                    }
                }

                outVal = "";
                if(relevant.TryGetValue((int)FormF.id, out outVal))
                {
                    angJSForm.Text += outVal;
                }
                if(FormF.FormFieldParentID == null)
                {
                    ngModelName.Add(FormF.name);
                    filedLabe = FormF.label;

                    filedBody += "<input type=\"file\" fileread=\"" + model + FormF.name + "\"   accept=\"image/*\" class=\"col-xs-10 col-sm-8\" ";
                    if(FormF.isReadOnly == 1)
                    {
                        filedBody += " ng-readonly=\"1\" ";
                    }
                    if(FormF.required == 1)
                    {
                        filedBody += " name=\"r_" + FormF.name + "\"";
                        if(outVal != null && outVal != "")
                        {
                            filedBody += " ng-required=\"currForm" + Regex.Match(outVal, "currForm(.+?)\">").Groups[1].Value + "\" />\n";
                        }
                        else filedBody += " required />\n";
                        filedBody += "<span style=\"color: #f1c409; padding: 5px;\" ng-show=\"mainForm.r_" + FormF.name + ".$error.required\"><i class=\"fa fa-warning\"></i></span>\n";
                    }
                    else filedBody += "/>";
                    //Retieve the existing image path
                    var val = (from v in responseValues
                               where v.formFieldId == FormF.id
                               select v.value).FirstOrDefault();
                    if(val != null)
                    {
                        filedBody += "<br/><a class=\"col-xs-10 col-sm-8\" href=\"" + val + "\" target=\"_blank\">" + val + "</a>";
                    }
                }
                else
                {
                    repVal = "";
                    roaster.TryGetValue((int)FormF.FormFieldParentID, out repVal);
                    if(repVal == null)
                        table.TryGetValue((int)FormF.FormFieldParentID, out repVal);

                    filedLabe = FormF.label;

                    filedBody += "  <input type=\"file\" fileread=\"rb_" + repVal + "." + FormF.name + "\"   accept=\"image/*\" class=\"col-xs-10 col-sm-8\" ";
                    ngModelNameSubForm.Add(FormF.name, "rb_" + repVal + ".");
                    if(FormF.isReadOnly == 1)
                    {
                        filedBody += " ng-readonly=\"1\" ";
                    }
                    if(FormF.required == 1)
                    {
                        filedBody += " name=\"r_" + FormF.name + "\"";
                        if(outVal != null && outVal != "")
                        {
                            filedBody += " ng-required=\"currForm" + Regex.Match(outVal, "currForm(.+?)\">").Groups[1].Value + "\" />\n";
                        }
                        else filedBody += " required />\n";
                        filedBody += "<span style=\"color: #f1c409; padding: 5px;\" ng-show=\"subForm" + repVal + ".r_" + FormF.name + ".$error.required\"><i class=\"fa fa-warning\"></i></span>\n";
                    }
                    else filedBody += "/>\n";

                }
                angJSForm.Text += getFieldBody(filedLabe, filedBody);

                if(outVal != null && outVal != "")
                {
                    angJSForm.Text += "</div>\n";
                }

                prevFieldID = (FormF.FormFieldParentID == null) ? 0 : (int)FormF.FormFieldParentID;
                break;

            default:
                if(prevFieldID != 0 && FormF.FormFieldParentID == null)
                {
                    angJSForm.Text += "</div></li></ul></div>\n";
                    if(closeRosterRelevant == 1)
                    {
                        angJSForm.Text += "</div>\n";
                        closeRosterRelevant = 0;
                    }
                }
                prevFieldID = (FormF.FormFieldParentID == null) ? 0 : (int)FormF.FormFieldParentID;
                #endregion
                break;
        }
    }
    /// <summary>
    /// Creates the HTML structure of the field passed in input.
    /// Each field is created using AngularJS directives.
    /// </summary>
    /// <param name="FormF">FormField to analyze</param>
    private void switchDataEntry(FormFieldExport FormF)
    {
        string filedLabe = "";
        string filedBody = "";
        switch (FormF.type)
        {
            case "DATE_FIELD":
                if (prevFieldID != 0 && FormF.FormFieldParentID == null)
                {
                    angJSForm.Text += "</div></li></ul></div>\n";
                    if (closeRosterRelevant == 1)
                    {
                        angJSForm.Text += "</div>\n";
                        closeRosterRelevant = 0;
                    }
                }
                outVal = "";
                if (relevant.TryGetValue((int)FormF.id, out outVal))
                {
                    angJSForm.Text += outVal;
                }
                if (FormF.FormFieldParentID == null)
                {
                    ngModelName.Add(FormF.name);
                    filedLabe = FormF.label;
                    filedBody = "<input type=\"text\" ng-model=\"" + model + FormF.name + "\" class=\"col-xs-10 col-sm-8\" ";
                    if (FormF.isReadOnly == 1)
                    {
                        filedBody += " ng-readonly=\"1\" ";
                    }
                    if (FormF.required == 1)
                    {
                        filedBody += " name=\"r_" + FormF.name + "\"";
                        if (outVal != null && outVal != "")
                        {
                            filedBody += " ng-required=\"currForm" + Regex.Match(outVal, "currForm(.+?)\">").Groups[1].Value + " jqdatepicker />\n";
                        }
                        else filedBody += " required jqdatepicker />\n";
                        filedBody += "<span style=\"color: #f1c409; padding: 5px;\" ng-show=\"mainForm.r_" + FormF.name + ".$error.required\"><i class=\"fa fa-warning\"></i></span>\n";
                    }
                    else filedBody += "/>\n";

                }
                else
                {
                    repVal = "";
                    roaster.TryGetValue((int)FormF.FormFieldParentID, out repVal);
                    if (repVal == null)
                        table.TryGetValue((int)FormF.FormFieldParentID, out repVal);
                    filedLabe = FormF.label;

                    filedBody += "<input type=\"text\" ng-model=\"rb_" + repVal + "." + FormF.name + "\" class=\"col-xs-10 col-sm-8\" ";
                    ngModelNameSubForm.Add(FormF.name, "rb_" + repVal + ".");
                    if (FormF.isReadOnly == 1)
                    {
                        filedBody += " ng-readonly=\"1\" ";
                    }
                    if (FormF.required == 1)
                    {
                        filedBody += " name=\"r_" + FormF.name + "\"";
                        if (outVal != null && outVal != "")
                        {
                            filedBody += " ng-required=\"currForm" + Regex.Match(outVal, "currForm(.+?)\">").Groups[1].Value + " jqdatepicker />\n";
                        }
                        else filedBody += " required jqdatepicker />\n";
                        filedBody += "<span style=\"color: #f1c409; padding: 5px;\" ng-show=\"subForm" + repVal + ".r_" + FormF.name + ".$error.required\"><i class=\"fa fa-warning\"></i></span>\n";
                    }
                    else filedBody += "/>\n";

                }
                angJSForm.Text += getFieldBody(filedLabe, filedBody);

                if (outVal != null && outVal != "")
                {
                    angJSForm.Text += "</div>\n";
                }

                prevFieldID = (FormF.FormFieldParentID == null) ? 0 : (int)FormF.FormFieldParentID;
                break;
            case "PHONE_NUMBER_FIELD":
            case "BARCODE":
            case "TEXT_FIELD":

                if (prevFieldID != 0 && FormF.FormFieldParentID == null)
                {
                    angJSForm.Text += "</div></li></ul></div>\n";
                    if (closeRosterRelevant == 1)
                    {
                        angJSForm.Text += "</div>\n";
                        closeRosterRelevant = 0;
                    }
                }

                outVal = "";
                if (FormF.FormFieldParentID == null)
                {
                    ngModelName.Add(FormF.name);

                    filedLabe = FormF.label;

                    if (relevant.TryGetValue((int)FormF.id, out outVal))
                    {
                        angJSForm.Text += outVal;
                    }

                    filedBody += "<input type=\"text\" ng-model=\"" + model + FormF.name + "\" class=\"col-xs-10 col-sm-8\" ";
                    if (FormF.isReadOnly == 1)
                    {
                        filedBody += " ng-readonly=\"1\" ";
                    }
                    if (FormF.required == 1)
                    {
                        filedBody += " name=\"r_" + FormF.name + "\"";
                        if (outVal != null && outVal != "")
                        {
                            filedBody += " ng-required=\"currForm" + Regex.Match(outVal, "currForm(.+?)\">").Groups[1].Value + "\" />\n";
                        }
                        else
                        {
                            filedBody += " required />\n";
                        }
                        filedBody += "<span style=\"color: #f1c409; padding: 5px;\" ng-show=\"mainForm.r_" + FormF.name + ".$error.required\"><i class=\"fa fa-warning\"></i></span>\n";
                    }
                    else
                    {
                        filedBody += "/>\n";
                    }
                }
                else
                {
                    repVal = "";
                    roaster.TryGetValue((int)FormF.FormFieldParentID, out repVal);
                    if (repVal == null)
                    {
                        table.TryGetValue((int)FormF.FormFieldParentID, out repVal);
                    }

                    filedLabe = FormF.label;

                    if (relevant.TryGetValue((int)FormF.id, out outVal))
                    {
                        angJSForm.Text += outVal.Replace("currForm", "rb_" + repVal);
                    }

                    filedBody += "  <input type=\"text\" ng-model=\"rb_" + repVal + "." + FormF.name + "\"  class=\"col-xs-10 col-sm-8\" ";
                    ngModelNameSubForm.Add(FormF.name, "rb_" + repVal + ".");
                    if (FormF.isReadOnly == 1)
                    {
                        filedBody += " ng-readonly=\"1\" ";
                    }
                    if (FormF.required == 1)
                    {
                        filedBody += " name=\"r_" + FormF.name + "\"";
                        if (outVal != null && outVal != "")
                        {
                            filedBody += " ng-required=\"rb_" + repVal + Regex.Match(outVal, "currForm(.+?)\">").Groups[1].Value + "\" />\n";
                        }
                        else
                        {
                            filedBody += " required />\n";
                        }
                        filedBody += "<span style=\"color: #f1c409; padding: 5px;\" ng-show=\"subForm" + repVal + ".r_" + FormF.name + ".$error.required\"><i class=\"fa fa-warning\"></i></span>\n";
                    }
                    else
                    {
                        filedBody += "/>\n";
                    }

                }
                angJSForm.Text += getFieldBody(filedLabe, filedBody);

                if (outVal != null && outVal != "")
                {
                    angJSForm.Text += "</div>\n";
                }

                prevFieldID = (FormF.FormFieldParentID == null) ? 0 : (int)FormF.FormFieldParentID;
                break;
            case "TEXT_AREA":
                if (prevFieldID != 0 && FormF.FormFieldParentID == null)
                {
                    angJSForm.Text += "</div></li></ul></div>\n";
                    if (closeRosterRelevant == 1)
                    {
                        angJSForm.Text += "</div>\n";
                        closeRosterRelevant = 0;
                    }
                }
                outVal = "";
                if (relevant.TryGetValue((int)FormF.id, out outVal))
                {
                    angJSForm.Text += outVal;
                }
                if (FormF.FormFieldParentID == null)
                {
                    ngModelName.Add(FormF.name);

                    filedLabe = FormF.label;
                    filedBody += "<textarea rows=\"2\" ng-model=\"" + model + FormF.name + "\" class=\"col-xs-10 col-sm-8\" ";
                    if (FormF.isReadOnly == 1)
                    {
                        filedBody += " ng-readonly=\"1\" ";
                    }
                    if (FormF.required == 1)
                    {
                        filedBody += " name=\"r_" + FormF.name + "\"";
                        if (outVal != null && outVal != "")
                        {
                            filedBody += " ng-required=\"currForm" + Regex.Match(outVal, "currForm(.+?)\">").Groups[1].Value + "\" ></textarea>\n";
                        }
                        else filedBody += " required ></textarea>\n";
                        filedBody += "<span style=\"color: #f1c409; padding: 5px;\" ng-show=\"mainForm.r_" + FormF.name + ".$error.required\"><i class=\"fa fa-warning\"></i></span> \n";
                    }
                    else filedBody += "></textarea> \n";
                }
                else
                {
                    repVal = "";
                    roaster.TryGetValue((int)FormF.FormFieldParentID, out repVal);
                    if (repVal == null)
                        table.TryGetValue((int)FormF.FormFieldParentID, out repVal);

                    filedLabe = FormF.label;
                    filedBody += "<textarea rows=\"2\" ng-model=\"rb_" + repVal + "." + FormF.name + "\"  class=\"col-xs-10 col-sm-8\"";
                    ngModelNameSubForm.Add(FormF.name, "rb_" + repVal + ".");
                    if (FormF.isReadOnly == 1)
                    {
                        filedBody += " ng-readonly=\"1\" ";
                    }
                    if (FormF.required == 1)
                    {
                        filedBody += " name=\"r_" + FormF.name + "\"";
                        if (outVal != null && outVal != "")
                        {
                            filedBody += " ng-required=\"currForm" + Regex.Match(outVal, "currForm(.+?)\">").Groups[1].Value + "\" ></textarea>\n";
                        }
                        else filedBody += " required ></textarea>\n";
                        filedBody += "<span style=\"color: #f1c409; padding: 5px;\" ng-show=\"subForm" + repVal + ".r_" + FormF.name + ".$error.required\"><i class=\"fa fa-warning\"></i></span> </div>\n";
                    }
                    else filedBody += "></textarea> </div>\n";

                }

                angJSForm.Text += getFieldBody(filedLabe, filedBody);
                if (outVal != null && outVal != "")
                {
                    angJSForm.Text += "</div>\n";
                }

                prevFieldID = (FormF.FormFieldParentID == null) ? 0 : (int)FormF.FormFieldParentID;
                break;
            case "CURRENCY_FIELD":
            case "NUMERIC_TEXT_FIELD":
                if (prevFieldID != 0 && FormF.FormFieldParentID == null)
                {
                    angJSForm.Text += "</div></li></ul></div>\n";
                    if (closeRosterRelevant == 1)
                    {
                        angJSForm.Text += "</div>\n";
                        closeRosterRelevant = 0;
                    }
                }
                outVal = "";
                if (relevant.TryGetValue((int)FormF.id, out outVal))
                {
                    angJSForm.Text += outVal;
                }
                if (FormF.FormFieldParentID == null)
                {
                    filedLabe = FormF.label;
                    ngModelName.Add(FormF.name);
                    filedBody += "<input type=\"number\" ng-pattern=\"/^[0-9]+(\\.[0-9]+)?$/\" step=\"any\" ng-model=\"" + model + FormF.name + "\" class=\"col-xs-10 col-sm-8\" ";
                    if (FormF.isReadOnly == 1 || FormF.calculated == 1)
                    {
                        filedBody += " ng-readonly=\"1\" ";
                    }
                    AddFieldConstrains(ref filedBody, FormF);
                    if (FormF.required == 1)
                    {
                        filedBody += " name=\"r_" + FormF.name + "\"";
                        //constr = "";
                        //if (constraint.TryGetValue((int)FormF.id, out constr))
                        //{
                        //    angJSForm.Text += constr;
                        //}
                        if (outVal != null && outVal != "")
                        {
                            ltlScript.Text += "$scope." + model + FormF.name + " = 0;";
                            filedBody += " ng-required=\"currForm" + Regex.Match(outVal, "currForm(.+?)\">").Groups[1].Value + "\" />\n";
                        }
                        else filedBody += " required />\n";
                        if (constr != null && constr != "")
                        {
                            filedBody += "<span ng-show=\"mainForm.r_" + FormF.name + ".$error.min || mainForm.r_" + FormF.name + ".$error.max\">Out of Bounds!</span>\n";
                        }
                        filedBody += "<span style=\"color: #f1c409; padding: 5px;\" ng-show=\"mainForm.r_" + FormF.name + ".$error.required\"><i class=\"fa fa-warning\"></i></span>";
                        filedBody += "<span style=\"color: red; padding: 5px;\" ng-show=\"mainForm.r_" + FormF.name + ".$error.number\"><i class=\"fa fa-warning\"></i></span>\n";
                    }
                    else if (constr != null && constr != "")
                    {
                        filedBody += " name=\"r_" + FormF.name + "\"";
                        filedBody += "/>\n<span ng-show=\"mainForm.r_" + FormF.name + ".$error.min || mainForm.r_" + FormF.name + ".$error.max\">Out of Bounds!</span>\n";
                    }
                    else filedBody += "/>\n";
                    if (FormF.calculated == 1)
                    {
                        if (FormF.formula != null)
                        {
                            bool isInModel = false;
                            foreach (string i in ngModelName)
                            {
                                if (FormF.formula.Contains(i))
                                {
                                    isInModel = true;
                                }
                            }
                            if (isInModel)
                            {
                                ltlScript.Text += "$scope.$watch('" + getFormula(FormF.formula) + "', function (value) {  $scope." + model + FormF.name + "= value;}, true);";
                            }
                            else
                            {
                                ltlScript.Text += getFormula(FormF.formula, "$scope." + model + FormF.name, repVal);
                            }
                        }
                    }
                }
                else
                {
                    repVal = "";
                    roaster.TryGetValue((int)FormF.FormFieldParentID, out repVal);
                    if (repVal == null)
                        table.TryGetValue((int)FormF.FormFieldParentID, out repVal);
                    filedLabe = FormF.label;
                    filedBody += "<input type=\"number\" ng-model=\"rb_" + repVal + "." + FormF.name + "\" class=\"col-xs-10 col-sm-8\" ";
                    ngModelNameSubForm.Add(FormF.name, "rb_" + repVal + ".");
                    ngModelCalculatedOutofModel.Add(FormF.name, "currForm." + repVal);
                    if (FormF.isReadOnly == 1 || FormF.calculated == 1)
                    {
                        filedBody += " ng-readonly=\"1\" ";
                    }
                    //constr = "";
                    //if (constraint.TryGetValue((int)FormF.id, out constr))
                    //{
                    //    filedBody += constr;
                    //}
                    AddFieldConstrains(ref filedBody, FormF);
                    if (FormF.required == 1)
                    {
                        filedBody += " name=\"r_" + FormF.name + "\"";
                        //constr = "";
                        //if (constraint.TryGetValue((int)FormF.id, out constr))
                        //{
                        //    angJSForm.Text += constr;
                        //}
                        if (outVal != null && outVal != "")
                        {
                            filedBody += " ng-required=\"currForm" + Regex.Match(outVal, "currForm(.+?)\">").Groups[1].Value + "\" />\n";
                        }
                        else filedBody += " required />\n";
                        if (constr != null && constr != "")
                        {
                            filedBody += "<span ng-show=\"subForm" + repVal + ".r_" + FormF.name + ".$error.min || subForm" + repVal + ".r_" + FormF.name + ".$error.max\">Out of Bounds!</span>\n";
                        }
                        filedBody += "<span style=\"color: #f1c409; padding: 5px;\" ng-show=\"subForm" + repVal + ".r_" + FormF.name + ".$error.required\"><i class=\"fa fa-warning\"></i></span>";
                        filedBody += "<span style=\"color: red; padding: 5px;\" ng-show=\"subForm" + repVal + ".r_" + FormF.name + ".$error.number\"><i class=\"fa fa-warning\"></i></span>\n";
                    }
                    else if (constr != null && constr != "")
                    {
                        filedBody += " name=\"r_" + FormF.name + "\"";
                        filedBody += "/>\n<span ng-show=\"subForm" + repVal + ".r_" + FormF.name + ".$error.min || subForm" + repVal + ".r_" + FormF.name + ".$error.max\">Out of Bounds!</span>\n";
                    }
                    else filedBody += "/>\n";
                    if (FormF.calculated == 1)
                    {
                        if (FormF.formula != null)
                        {
                            ltlScript.Text += "$scope.$watch('currForm." + repVal + "', function (value) { var i = 0;for(i = 0; i < value.length; i++) value[i]." + FormF.name + " = " + getFormula(FormF.formula, repVal) + ";}, true);";
                        }
                    }
                }
                angJSForm.Text += getFieldBody(filedLabe, filedBody);
                if (outVal != null && outVal != "")
                {
                    angJSForm.Text += "</div>\n";
                }

                prevFieldID = (FormF.FormFieldParentID == null) ? 0 : (int)FormF.FormFieldParentID;
                break;
            case "DROP_DOWN_LIST":
                if (prevFieldID != 0 && FormF.FormFieldParentID == null)
                {
                    angJSForm.Text += "</div></li></ul></div>\n";
                    if (closeRosterRelevant == 1)
                    {
                        angJSForm.Text += "</div>\n";
                        closeRosterRelevant = 0;
                    }
                }
                if (!ltlScript.Text.Contains("$scope.options" + (int)FormF.survey_id + "="))
                {
                    script = "";
                    script += "$scope.options" + (int)FormF.survey_id + "= [";
                    foreach (SurveyElement se in getOptions((int)FormF.survey_id))
                    {
                        script += "{value:\"" + se.value.Replace("'", @"\\'").Replace("\r\n", " ").Replace("\n", " ") + "\"},";
                    }
                    ltlScript.Text += script.Substring(0, script.Length - 1);
                    ltlScript.Text += "];";
                }

                outVal = "";
                if (relevant.TryGetValue((int)FormF.id, out outVal))
                {
                    angJSForm.Text += outVal;
                }
                filedLabe = FormF.label;

                if (FormF.FormFieldParentID == null)
                {
                    ngModelName.Add(FormF.name);

                    filedBody += "<select ng-model=\"" + model + FormF.name + "\" class=\"col-xs-10 col-sm-8\" ng-options=\"o.value for o in options" + (int)FormF.survey_id + "\"";

                    if (FormF.required == 1)
                    {
                        filedBody += " name=\"r_" + FormF.name + "\"";
                        if (outVal != null && outVal != "")
                        {
                            filedBody += " ng-required=\"currForm" + Regex.Match(outVal, "currForm(.+?)\">").Groups[1].Value + "\" ></select>\n";
                        }
                        else filedBody += " required ></select>";
                        filedBody += "<span style=\"color: #f1c409; padding: 5px;\" ng-show=\"mainForm.r_" + FormF.name + ".$error.required\"><i class=\"fa fa-warning\"></i></span>\n";
                    }
                    else filedBody += "></select>\n";
                }
                else
                {
                    repVal = "";
                    roaster.TryGetValue((int)FormF.FormFieldParentID, out repVal);
                    if (repVal == null)
                        table.TryGetValue((int)FormF.FormFieldParentID, out repVal);
                    filedBody += "<select ng-model=\"rb_" + repVal + "." + FormF.name + "\" class=\"col-xs-10 col-sm-8\" ng-options=\"o.value for o in options" + (int)FormF.survey_id + "\"";

                    if (!ngModelNameSubForm.ContainsKey(FormF.name))
                        ngModelNameSubForm.Add(FormF.name, "rb_" + repVal + ".");
                    if (FormF.required == 1)
                    {
                        filedBody += " name=\"r_" + FormF.name + "\"";
                        if (outVal != null && outVal != "")
                        {
                            filedBody += " ng-required=\"currForm" + Regex.Match(outVal, "currForm(.+?)\">").Groups[1].Value + "\" /></select>\n";
                        }
                        else filedBody += " required /></select>\n";
                        filedBody += "<span style=\"color: #f1c409; padding: 5px;\" ng-show=\"subForm" + repVal + ".r_" + FormF.name + ".$error.required\"><i class=\"fa fa-warning\"></i></span>\n";
                    }
                    else filedBody += "/></select>\n";
                }

                angJSForm.Text += getFieldBody(filedLabe, filedBody);
                if (outVal != null && outVal != "")
                {
                    angJSForm.Text += "</div>\n";
                }

                prevFieldID = (FormF.FormFieldParentID == null) ? 0 : (int)FormF.FormFieldParentID;
                break;
            case "RADIO_BUTTON":
                if (prevFieldID != 0 && FormF.FormFieldParentID == null)
                {
                    angJSForm.Text += "</div></li></ul></div>\n";
                    if (closeRosterRelevant == 1)
                    {
                        angJSForm.Text += "</div>\n";
                        closeRosterRelevant = 0;
                    }
                }
                outVal = "";
                if (relevant.TryGetValue((int)FormF.id, out outVal))
                {
                    angJSForm.Text += outVal;
                }
                filedLabe = FormF.label;

                foreach (SurveyElement se in getOptions((int)FormF.survey_id))
                {

                    if (FormF.FormFieldParentID == null)
                    {
                        ngModelName.Add(FormF.name);

                        filedBody += "<label class=\"inline\"><input type=\"radio\" class=\"ace\"  ng-model=\"" + model + FormF.name + "\" value=\"" + se.value + "\"";
                        if (FormF.required == 1)
                        {
                            filedBody += " name=\"r_" + FormF.name + "\"";
                            if (outVal != null && outVal != "")
                            {
                                filedBody += " ng-required=\"currForm" + Regex.Match(outVal, "currForm(.+?)\">").Groups[1].Value + "\" />\n";
                                filedBody += "<span class=\"lbl\"> " + se.value + "</span></label> \n";
                            }
                            else
                            {
                                filedBody += " required ><span class=\"lbl\"> " + se.value + "</span></label>\n";
                            }
                            //  angJSForm.Text += "<span style=\"color: #f1c409; padding: 5px;\" ng-show=\"mainForm.r_" + FormF.name + ".$error.required\"><i class=\"fa fa-warning\"></i></span></div>\n";
                        }
                        else
                        {
                            filedBody += " ><span class=\"lbl\"> " + se.value + "</span></label>\n";
                        }

                        //angJSForm.Text += "<div class=\"right\"><label>" + se.value + "</label><input type=\"radio\" ng-model=\"" + model + FormF.name + "\" value=\"" + se.value + "\"";
                        //if (FormF.required == 1)
                        //{
                        //    angJSForm.Text += " name=\"r_" + FormF.name + "\"";
                        //    if (outVal != null && outVal != "")
                        //    {
                        //        angJSForm.Text += " ng-required=\"currForm" + Regex.Match(outVal, "currForm(.+?)\">").Groups[1].Value + "\" />\n";
                        //    }
                        //    else angJSForm.Text += " required />\n";
                        //    angJSForm.Text += "<span style=\"color: #f1c409; padding: 5px;\" ng-show=\"mainForm.r_" + FormF.name + ".$error.required\"><i class=\"fa fa-warning\"></i></span></div>\n";
                        //}
                        //else angJSForm.Text += "/></div>\n";
                    }
                    else
                    {
                        //repVal = "";
                        //roaster.TryGetValue((int)FormF.FormFieldParentID, out repVal);
                        //if (repVal == null)
                        //    table.TryGetValue((int)FormF.FormFieldParentID, out repVal);
                        //angJSForm.Text += "<div class=\"left clear\"><label>" + se.value + "</label></div><div class=\"right\"><input type=\"radio\" ng-model=\"rb_" + repVal + "." + FormF.name + "\" value=\"" + se.value + "\"";
                        //if (!ngModelNameSubForm.ContainsKey(FormF.name))
                        //    ngModelNameSubForm.Add(FormF.name, "rb_" + repVal + ".");
                        //if (FormF.required == 1)
                        //{
                        //    angJSForm.Text += " name=\"r_{{$index}}" + FormF.name + "\"";
                        //    if (outVal != null && outVal != "")
                        //    {
                        //        angJSForm.Text += " ng-required=\"currForm" + Regex.Match(outVal, "currForm(.+?)\">").Groups[1].Value + "\" />\n";
                        //    }
                        //    else angJSForm.Text += " required />\n";
                        //    angJSForm.Text += "<span style=\"color: #f1c409; padding: 5px;\" ng-show=\"subForm" + repVal + ".r_" + FormF.name + ".$error.required\"><i class=\"fa fa-warning\"></i></span></div>\n";
                        //}
                        //else angJSForm.Text += "/></div>\n";

                        repVal = "";
                        roaster.TryGetValue((int)FormF.FormFieldParentID, out repVal);

                        if (repVal == null)
                            table.TryGetValue((int)FormF.FormFieldParentID, out repVal);

                        filedBody += "<label class=\"inline\"><input type=\"radio\" class=\"ace\"  ng-model=\"rb_" + repVal + "." + FormF.name + "\" value=\"" + se.value + "\"";

                        if (!ngModelNameSubForm.ContainsKey(FormF.name))
                            ngModelNameSubForm.Add(FormF.name, "rb_" + repVal + ".");
                        if (FormF.required == 1)
                        {
                            filedBody += " name=\"r_{{$index}}" + FormF.name + "\"";
                            if (outVal != null && outVal != "")
                            {
                                filedBody += " ng-required=\"currForm" + Regex.Match(outVal, "currForm(.+?)\">").Groups[1].Value + "\" />\n";
                                filedBody += "<span class=\"lbl\"> " + se.value + "</span></label> \n";
                            }
                            else
                            {
                                filedBody += " required ><span class=\"lbl\"> " + se.value + "</span></label>\n";
                            }

                        }
                        else
                        {
                            filedBody += " ><span class=\"lbl\"> " + se.value + "</span></label> \n";
                        }

                    }
                }
                if (FormF.FormFieldParentID == null)
                {
                    filedBody += "<span style=\"color: #f1c409; padding: 5px;\" ng-show=\"mainForm.r_" + FormF.name + ".$error.required\"><i class=\"fa fa-warning\"></i></span> \n";
                }
                else
                {

                    filedBody += "<span style=\"color: #f1c409; padding: 5px;\" ng-show=\"subForm" + repVal + ".r_" + FormF.name + ".$error.required\"><i class=\"fa fa-warning\"></i></span> \n";

                }
                if (outVal != null && outVal != "")
                {
                    filedBody += "</div>\n";
                }
                angJSForm.Text += getFieldBody(filedLabe, filedBody);

                prevFieldID = (FormF.FormFieldParentID == null) ? 0 : (int)FormF.FormFieldParentID;
                break;
            case "CHECK_BOX":
                if (prevFieldID != 0 && FormF.FormFieldParentID == null)
                {
                    angJSForm.Text += "</div></li></ul></div>\n";
                    if (closeRosterRelevant == 1)
                    {
                        angJSForm.Text += "</div>\n";
                        closeRosterRelevant = 0;
                    }
                }
                outVal = "";
                if (relevant.TryGetValue((int)FormF.id, out outVal))
                {
                    angJSForm.Text += outVal;
                }
                if (FormF.FormFieldParentID == null)
                {
                    filedLabe = FormF.label;

                    ngModelName.Add(FormF.name);
                    ltlScript.Text += "$scope." + model + FormF.name + " = false;";

                    filedBody += "<input type=\"checkbox\" ng-model=\"" + model + FormF.name + "\"";
                    if (FormF.isReadOnly == 1 || FormF.calculated == 1)
                    {
                        filedBody += " ng-readonly=\"1\" ";
                    }
                    constr = "";
                    if (constraint.TryGetValue((int)FormF.id, out constr))
                    {
                        filedBody += constr;
                    }
                    filedBody += "/>\n";
                    //if (FormF.required == 1) //s3 we don't want the checkbox to be always red and requrired.
                    //{
                    //    filedBody += " name=\"r_" + FormF.name + "\"";
                    //    //constr = "";
                    //    //if (constraint.TryGetValue((int)FormF.id, out constr))
                    //    //{
                    //    //    angJSForm.Text += constr;
                    //    //}
                    //    if (outVal != null && outVal != "")
                    //    {
                    //        filedBody += " ng-required=\"currForm" + Regex.Match(outVal, "currForm(.+?)\">").Groups[1].Value + "\" />\n";
                    //    }
                    //    else filedBody += " required />\n";
                    //    filedBody += "<span style=\"color: #f1c409; padding: 5px;\" ng-show=\"mainForm.r_" + FormF.name + ".$error.required\"><i class=\"fa fa-warning\"></i></span>\n";
                    //}
                    //else filedBody += "/>\n";
                }
                else
                {
                    repVal = "";
                    filedLabe = FormF.label;
                    roaster.TryGetValue((int)FormF.FormFieldParentID, out repVal);
                    if (repVal == null)
                        table.TryGetValue((int)FormF.FormFieldParentID, out repVal);
                    filedBody += "<input type=\"checkbox\" ng-model=\"rb_" + repVal + "." + FormF.name + "\"";
                    ngModelNameSubForm.Add(FormF.name, "rb_" + repVal + ".");
                    if (FormF.isReadOnly == 1 || FormF.calculated == 1)
                    {
                        filedBody += " ng-readonly=\"1\" ";
                    }
                    constr = "";
                    if (constraint.TryGetValue((int)FormF.id, out constr))
                    {
                        filedBody += constr;
                    }
                    //if (FormF.required == 1)//s3 we don't want the checkbox to be always red and requrired.
                    //{
                    //    filedBody += " name=\"r_" + FormF.name + "\"";
                    //    //constr = "";
                    //    //if (constraint.TryGetValue((int)FormF.id, out constr))
                    //    //{
                    //    //    angJSForm.Text += constr;
                    //    //}
                    //    if (outVal != null && outVal != "")
                    //    {
                    //        filedBody += " ng-required=\"currForm" + Regex.Match(outVal, "currForm(.+?)\">").Groups[1].Value + "\" />\n";
                    //    }
                    //    else filedBody += " required />\n";
                    //    filedBody += "<span style=\"color: #f1c409; padding: 5px;\" ng-show=\"subForm" + repVal + ".r_" + FormF.name + ".$error.required\"><i class=\"fa fa-warning\"></i></span>\n";
                    //}
                    //else filedBody += "/>\n";
                    filedBody += "/>\n";
                }
                angJSForm.Text += getFieldBody(filedLabe, filedBody);
                if (outVal != null && outVal != "")
                {
                    angJSForm.Text += "</div>\n";
                }
                prevFieldID = (FormF.FormFieldParentID == null) ? 0 : (int)FormF.FormFieldParentID;
                break;
            case "REPEATABLES_BASIC":
                if (prevFieldID != 0 && FormF.FormFieldParentID == null)
                {
                    angJSForm.Text += "</div></li></ul></div>\n";
                    if (closeRosterRelevant == 1)
                    {
                        angJSForm.Text += "</div>\n";
                        closeRosterRelevant = 0;
                    }
                }
                outVal = "";
                closeRosterRelevant = 0;
                if (relevant.TryGetValue((int)FormF.id, out outVal))
                {
                    angJSForm.Text += outVal;
                    closeRosterRelevant = 1;
                }

                ltlScript.Text += "$scope." + model + FormF.name + " = [];";
                checkFieldForRoaster((int)FormF.id, FormF.name);
                roaster.Add((int)FormF.id, FormF.name);
                angJSForm.Text += "<div class=\"col-sm-9 form-group\"><label>Roster " + FormF.label + "</label><br/>\n";
                angJSForm.Text += "<a ng-click=\"addNew" + FormF.name + "()\"><i class=\"fa fa-plus\"></i> Add New " + FormF.name + "</a></div><div class=\"col-sm-11 form-group\"><ul>";
                angJSForm.Text += "<li ng-repeat=\"rb_" + FormF.name + " in " + model + FormF.name + "\" ng-form=\"subForm" + FormF.name + "\">\n<div style=\"overflow: hidden;\">";
                prevFieldID = (FormF.FormFieldParentID == null) ? 0 : (int)FormF.FormFieldParentID;
                break;
            case "REPEATABLES":
                if (prevFieldID != 0 && FormF.FormFieldParentID == null)
                {
                    angJSForm.Text += "</div></li></ul></div>\n";
                    if (closeRosterRelevant == 1)
                    {
                        angJSForm.Text += "</div>\n";
                        closeRosterRelevant = 0;
                    }
                }
                outVal = "";
                closeRosterRelevant = 0;
                if (relevant.TryGetValue((int)FormF.id, out outVal))
                {
                    angJSForm.Text += outVal;
                    closeRosterRelevant = 1;
                }
                prevFieldID = (FormF.FormFieldParentID == null) ? 0 : (int)FormF.FormFieldParentID;
                ltlScript.Text += "$scope." + model + FormF.name + " = [";
                checkFieldForTable((int)FormF.survey_id);
                table.Add((int)FormF.id, FormF.name);
                angJSForm.Text += "<div class=\"col-sm-9 form-group\"><label>" + FormF.label + "</label><br/>\n";
                angJSForm.Text += "<div class=\"col-sm-9 form-group\"><ul><li ng-repeat=\"rb_" + FormF.name + " in " + model + FormF.name + "\" ng-form=\"subForm" + FormF.name + "\">\n<div style=\"overflow: hidden;\">";
                angJSForm.Text += "<label>{{rb_" + FormF.name + ".value}}</label><br />";
                break;
            case "SEPARATOR":
                if (prevFieldID != 0 && FormF.FormFieldParentID == null)
                {
                    angJSForm.Text += "</div></li></ul></div>\n";
                    if (closeRosterRelevant == 1)
                    {
                        angJSForm.Text += "</div>\n";
                        closeRosterRelevant = 0;
                    }
                }
                angJSForm.Text += "<div class=\"clear\"><hr /></div>\n";
                prevFieldID = (FormF.FormFieldParentID == null) ? 0 : (int)FormF.FormFieldParentID;
                break;
            case "TRUNCATED_TEXT":
            case "WRAPPED_TEXT":

                if (prevFieldID != 0 && FormF.FormFieldParentID == null)
                {
                    angJSForm.Text += "</div></li></ul></div>\n";
                    if (closeRosterRelevant == 1)
                    {
                        angJSForm.Text += "</div>\n";
                        closeRosterRelevant = 0;
                    }
                }
                outVal = "";
                if (relevant.TryGetValue((int)FormF.id, out outVal))
                {
                    angJSForm.Text += outVal;
                }
                if (FormF.FormFieldParentID == null)
                {
                    angJSForm.Text += "<div class=\"col-sm-9 form-group\"><label style=\"font-weight: bold;\" ng-model=\"" + model + FormF.name + "\">" + FormF.label + "</label></div>\n";
                }
                else
                {
                    repVal = "";
                    roaster.TryGetValue((int)FormF.FormFieldParentID, out repVal);
                    if (repVal == null)
                        table.TryGetValue((int)FormF.FormFieldParentID, out repVal);
                    angJSForm.Text += "<div class=\"col-sm-9 form-group\"><label style=\"font-weight: bold;\" ng-model=\"rb_" + repVal + "." + FormF.name + "\">" + FormF.label + "</label></div>\n";
                }

                if (outVal != null && outVal != "")
                {
                    angJSForm.Text += "</div>\n";
                }
                prevFieldID = (FormF.FormFieldParentID == null) ? 0 : (int)FormF.FormFieldParentID;
                break;
            case "GEOLOCATION":
                if (prevFieldID != 0 &&
                    FormF.FormFieldParentID == null)
                {
                    angJSForm.Text += "</div></li></ul></div>\n";
                    if (closeRosterRelevant == 1)
                    {
                        angJSForm.Text += "</div>\n";
                        closeRosterRelevant = 0;
                    }
                }

                outVal = "";
                if (relevant.TryGetValue((int)FormF.id, out outVal))
                {
                    angJSForm.Text += outVal;
                }
                if (FormF.FormFieldParentID == null)
                {
                    filedLabe = FormF.label;
                    ngModelName.Add(FormF.name);
                    filedBody += "  <input type=\"number\" class=\"col-xs-5 col-sm-4\" min=\"-90\" max=\"90\" placeholder=\"Lat\" ng-model=\"" + model + FormF.name + "LatDE\""; //*
                    constr = ""; //*
                    if (constraint.TryGetValue((int)FormF.id, out constr))
                    {
                        filedBody += constr;
                    }
                    filedBody += " name=\"r_" + FormF.name + "LatDE\"";
                    if (FormF.required == 1)
                    {
                        if (!string.IsNullOrEmpty(outVal))
                        {
                            ltlScript.Text += "$scope." + model + FormF.name + "LatDE = 0;";
                            filedBody += " ng-required=\"currForm" + Regex.Match(outVal, "currForm(.+?)\">").Groups[1].Value + "\" />\n";
                        }
                        else filedBody += " required />\n";
                        filedBody += "<span style=\"color: #f1c409; padding: 5px;\" ng-show=\"mainForm.r_" + FormF.name + "LatDE.$error.required || mainForm.r_" + FormF.name + "LatDE.$error.number\"><i class=\"fa fa-warning\"></i></span> \n";
                    }
                    else filedBody += "/>";

                    filedBody += " <input type=\"number\" class=\"col-xs-5 col-sm-4\" min=\"-180\" max=\"180\" placeholder=\"Long\"  ng-model=\"" + model + FormF.name + "LongDE\"";
                    constr = "";
                    if (constraint.TryGetValue((int)FormF.id, out constr))
                    {
                        filedBody += constr;
                    }
                    filedBody += " name=\"r_" + FormF.name + "LongDE\"";
                    if (FormF.required == 1)
                    {
                        if (outVal != null && outVal != "")
                        {
                            ltlScript.Text += "$scope." + model + FormF.name + "LongDE = 0;";
                            filedBody += " ng-required=\"currForm" + Regex.Match(outVal, "currForm(.+?)\">").Groups[1].Value + "\" />\n";
                        }
                        else filedBody += " required />\n";
                        filedBody += "<span style=\"color: #f1c409; padding: 5px;\" ng-show=\"mainForm.r_" + FormF.name + "LongDE.$error.required\"><i class=\"fa fa-warning\"></i></span>";
                        filedBody += "<span style=\"color: red; padding: 5px;\" ng-show=\"mainForm.r_" + FormF.name + "LongDE.$error.number\"><i class=\"fa fa-warning\"></i></span> \n";
                    }
                    else filedBody += "/>";
                    filedBody += "<span style=\"color: red; padding: 5px;\" ng-show=\"mainForm.r_" + FormF.name + "LatDE.$error.min || mainForm.r_" + FormF.name + "LatDE.$error.max\"><i class=\"fa fa-warning\"></i>Invalid Coords!</span>\n";
                    filedBody += "<span style=\"color: red; padding: 5px;\" ng-show=\"mainForm.r_" + FormF.name + "LongDE.$error.min || mainForm.r_" + FormF.name + "LongDE.$error.max\"><i class=\"fa fa-warning\"></i>Invalid Coords!</span>\n";
                    filedBody += " \n";
                }
                else
                {
                    repVal = "";
                    roaster.TryGetValue((int)FormF.FormFieldParentID, out repVal);
                    if (repVal == null)
                        table.TryGetValue((int)FormF.FormFieldParentID, out repVal);

                    filedLabe = FormF.label;
                    filedBody += "Lat: <input type=\"number\" min=\"-90\" max=\"90\" ng-model=\"rb_" + repVal + "." + FormF.name + "LatDE\"";
                    ngModelNameSubForm.Add(FormF.name, "rb_" + repVal + ".");
                    if (FormF.isReadOnly == 1 ||
                        FormF.calculated == 1)
                    {
                        filedBody += " ng-readonly=\"1\" ";
                    }
                    constr = ""; //*
                    if (constraint.TryGetValue((int)FormF.id, out constr))
                    {
                        filedBody += constr;
                    }
                    filedBody += " name=\"r_" + FormF.name + "LatDE\"";
                    if (FormF.required == 1)
                    {
                        if (!string.IsNullOrEmpty(outVal))
                        {
                            filedBody += " ng-required=\"currForm" + Regex.Match(outVal, "currForm(.+?)\">").Groups[1].Value + "\" />\n";
                        }
                        else filedBody += " required />\n";
                        filedBody += "<span style=\"color: #f1c409; padding: 5px;\" ng-show=\"subForm" + repVal + ".r_" + FormF.name + "LatDE.$error.required\"><i class=\"fa fa-warning\"></i></span>";
                        filedBody += "<span style=\"color: red; padding: 5px;\" ng-show=\"subForm" + repVal + ".r_" + FormF.name + "LatDE.$error.number\"><i class=\"fa fa-warning\"></i></span>\n";
                    }
                    else filedBody += "/>";

                    filedBody += " Long: <input type=\"number\" min=\"-180\" max=\"180\" ng-model=\"rb_" + repVal + "." + FormF.name + "LongDE\"";
                    ngModelNameSubForm.Add(FormF.name, "rb_" + repVal + ".");
                    if (FormF.isReadOnly == 1 || FormF.calculated == 1)
                    {
                        filedBody += " ng-readonly=\"1\" ";
                    }
                    constr = "";
                    if (constraint.TryGetValue((int)FormF.id, out constr))
                    {
                        filedBody += constr;
                    }
                    filedBody += " name=\"r_" + FormF.name + "LongDE\"";
                    if (FormF.required == 1)
                    {
                        if (outVal != null && outVal != "")
                        {
                            filedBody += " ng-required=\"currForm" + Regex.Match(outVal, "currForm(.+?)\">").Groups[1].Value + "\" />\n";
                        }
                        else filedBody += " required />\n";

                        filedBody += "<span style=\"color: #f1c409; padding: 5px;\" ng-show=\"subForm" + repVal + ".r_" + FormF.name + "LongDE.$error.required\"><i class=\"fa fa-warning\"></i></span>";
                        filedBody += "<span style=\"color: red; padding: 5px;\" ng-show=\"subForm" + repVal + ".r_" + FormF.name + "LongDE.$error.number\"><i class=\"fa fa-warning\"></i></span>\n";
                    }
                    else filedBody += "/>";
                    filedBody += "<span style=\"color: red; padding: 5px;\" ng-show=\"subForm" + repVal + ".r_" + FormF.name + "LatDE.$error.min || subForm" + repVal + ".r_" + FormF.name + "LatDE.$error.max\"><i class=\"fa fa-warning\"></i>Invalid coords!</span>\n";
                    filedBody += "<span style=\"color: red; padding: 5px;\" ng-show=\"subForm" + repVal + ".r_" + FormF.name + "LongDE.$error.min || subForm" + repVal + ".r_" + FormF.name + "LongDE.$error.max\"><i class=\"fa fa-warning\"></i>Invalid coords!</span>\n";
                    filedBody += "\n";
                }
                angJSForm.Text += getFieldBody(filedLabe, filedBody);
                if (!string.IsNullOrEmpty(outVal))
                {
                    angJSForm.Text += "</div>\n";
                }

                prevFieldID = (FormF.FormFieldParentID == null) ? 0 : (int)FormF.FormFieldParentID;
                break;
            case "EMAIL_FIELD":
                if (prevFieldID != 0 && FormF.FormFieldParentID == null)
                {
                    angJSForm.Text += "</div></li></ul></div>\n";
                    if (closeRosterRelevant == 1)
                    {
                        angJSForm.Text += "</div>\n";
                        closeRosterRelevant = 0;
                    }
                }
                outVal = "";
                if (relevant.TryGetValue((int)FormF.id, out outVal))
                {
                    angJSForm.Text += outVal;
                }
                if (FormF.FormFieldParentID == null)
                {

                    filedLabe = FormF.label;
                    ngModelName.Add(FormF.name);
                    filedBody += "<input type=\"email\" ng-model=\"" + model + FormF.name + "\" class=\"col-xs-10 col-sm-8\" ";
                    if (FormF.isReadOnly == 1)
                    {
                        filedBody += " ng-readonly=\"1\" ";
                    }
                    if (FormF.required == 1)
                    {
                        filedBody += " name=\"r_" + FormF.name + "\"";
                        if (outVal != null && outVal != "")
                        {
                            filedBody += " ng-required=\"currForm" + Regex.Match(outVal, "currForm(.+?)\">").Groups[1].Value + "\" />\n";
                        }
                        else filedBody += " required />\n";
                        filedBody += "<span style=\"color: #f1c409; padding: 5px;\" ng-show=\"mainForm.r_" + FormF.name + ".$error.required\"><i class=\"fa fa-warning\"></i></span>\n";
                    }
                    else filedBody += "/>\n";
                }
                else
                {
                    repVal = "";
                    roaster.TryGetValue((int)FormF.FormFieldParentID, out repVal);
                    if (repVal == null)
                        table.TryGetValue((int)FormF.FormFieldParentID, out repVal);

                    filedLabe = FormF.label;
                    filedBody += "<input type=\"email\" ng-model=\"rb_" + repVal + "." + FormF.name + "\"";
                    ngModelNameSubForm.Add(FormF.name, "rb_" + repVal + ".");
                    if (FormF.isReadOnly == 1)
                    {
                        filedBody += " ng-readonly=\"1\" ";
                    }
                    if (FormF.required == 1)
                    {
                        filedBody += " name=\"r_" + FormF.name + "\"";
                        if (outVal != null && outVal != "")
                        {
                            filedBody += " ng-required=\"currForm" + Regex.Match(outVal, "currForm(.+?)\">").Groups[1].Value + "\" />\n";
                        }
                        else filedBody += " required />\n";
                        filedBody += "<span style=\"color: #f1c409; padding: 5px;\" ng-show=\"subForm" + repVal + ".r_" + FormF.name + ".$error.required\"><i class=\"fa fa-warning\"></i></span>\n";
                    }
                    else filedBody += "/> \n";
                }
                angJSForm.Text += getFieldBody(filedLabe, filedBody);
                if (outVal != null && outVal != "")
                {
                    angJSForm.Text += "</div>\n";
                }

                prevFieldID = (FormF.FormFieldParentID == null) ? 0 : (int)FormF.FormFieldParentID;
                break;
            case "IMAGE":

                if (prevFieldID != 0 && FormF.FormFieldParentID == null)
                {
                    angJSForm.Text += "</div></li></ul></div>\n";
                    if (closeRosterRelevant == 1)
                    {
                        angJSForm.Text += "</div>\n";
                        closeRosterRelevant = 0;
                    }
                }

                outVal = "";
                if (relevant.TryGetValue((int)FormF.id, out outVal))
                {
                    angJSForm.Text += outVal;
                }
                if (FormF.FormFieldParentID == null)
                {
                    ngModelName.Add(FormF.name);

                    filedLabe = FormF.label;

                    filedBody += "<input type=\"file\" fileread=\"" + model + FormF.name + "\"   accept=\"image/*\" class=\"col-xs-10 col-sm-8\" ";
                    if (FormF.isReadOnly == 1)
                    {
                        filedBody += " ng-readonly=\"1\" ";
                    }
                    if (FormF.required == 1)
                    {
                        filedBody += " name=\"r_" + FormF.name + "\"";
                        if (outVal != null && outVal != "")
                        {
                            filedBody += " ng-required=\"currForm" + Regex.Match(outVal, "currForm(.+?)\">").Groups[1].Value + "\" />\n";
                        }
                        else filedBody += " required />\n";
                        filedBody += "<span style=\"color: #f1c409; padding: 5px;\" ng-show=\"mainForm.r_" + FormF.name + ".$error.required\"><i class=\"fa fa-warning\"></i></span>\n";
                    }
                    else filedBody += "/>\n";
                }
                else
                {
                    repVal = "";
                    roaster.TryGetValue((int)FormF.FormFieldParentID, out repVal);
                    if (repVal == null)
                        table.TryGetValue((int)FormF.FormFieldParentID, out repVal);

                    filedLabe = FormF.label;

                    filedBody += "  <input type=\"file\" fileread=\"rb_" + repVal + "." + FormF.name + "\"   accept=\"image/*\" class=\"col-xs-10 col-sm-8\" ";
                    ngModelNameSubForm.Add(FormF.name, "rb_" + repVal + ".");
                    if (FormF.isReadOnly == 1)
                    {
                        filedBody += " ng-readonly=\"1\" ";
                    }
                    if (FormF.required == 1)
                    {
                        filedBody += " name=\"r_" + FormF.name + "\"";
                        if (outVal != null && outVal != "")
                        {
                            filedBody += " ng-required=\"currForm" + Regex.Match(outVal, "currForm(.+?)\">").Groups[1].Value + "\" />\n";
                        }
                        else filedBody += " required />\n";
                        filedBody += "<span style=\"color: #f1c409; padding: 5px;\" ng-show=\"subForm" + repVal + ".r_" + FormF.name + ".$error.required\"><i class=\"fa fa-warning\"></i></span>\n";
                    }
                    else filedBody += "/>\n";

                }
                angJSForm.Text += getFieldBody(filedLabe, filedBody);

                if (outVal != null && outVal != "")
                {
                    angJSForm.Text += "</div>\n";
                }

                prevFieldID = (FormF.FormFieldParentID == null) ? 0 : (int)FormF.FormFieldParentID;
                break;

            default:
                if (prevFieldID != 0 && FormF.FormFieldParentID == null)
                {
                    angJSForm.Text += "</div></li></ul></div>\n";
                    if (closeRosterRelevant == 1)
                    {
                        angJSForm.Text += "</div>\n";
                        closeRosterRelevant = 0;
                    }
                }
                prevFieldID = (FormF.FormFieldParentID == null) ? 0 : (int)FormF.FormFieldParentID;
                break;
        }
    }
 /// <summary>
 /// Adds contraints on the given field. Example: min and max on the numeric field.
 /// </summary>
 /// <param name="fieldContraints"></param>
 /// <param name="fieldBody"></param>
 /// <param name="formFExp"></param>
 /// <author>Saad Mansour</author>
 private void AddFieldConstrains(ref string fieldBody, FormFieldExport formFExp)
 {
     try
     {
         constr = "";
         List<FieldConstraintRel> currFieldConstraints = (from fc in fieldConstraintRel
                                                          where fc.FormFieldID == (int)formFExp.id
                                                          select fc).ToList();
         foreach (FieldConstraintRel fcr in currFieldConstraints)
         {
             if (constraint.TryGetValue(fcr.ConstraintID, out constr))
             {
                 fieldBody += constr;
             }
         }
     }
     catch (Exception ex)
     {
         LogUtils.WriteErrorLog(ex.ToString());
     }
 }
 /// <summary>
 /// Returns Field Name With Form Name, ex: mainForm.r_age.
 /// </summary>
 /// <param name="formFX"></param>
 /// <returns></returns>
 /// <author>Saad Mansour</author>
 private string GetFieldNameWithFormName(FormFieldExport formFX)
 {
     if (formFX != null)
     {
         return "mainForm.r_" + formFX.name;
     }
     else
         return string.Empty;
 }