Created
September 6, 2021 09:53
-
-
Save bjoerntx/b419af47b298fa671681c30782d3d3f5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function successFunc(data, status) { | |
$("#smartForm").empty(); | |
data.forEach(section => { | |
var fieldset = $("<form><fieldset><legend>" + section.Name + "</legend></fieldset></form>").appendTo("#smartForm"); | |
section.FormFields.forEach(formField => { | |
switch (formField.TypeName) { | |
case "SmartTextFormField": | |
fieldset.append($("<div class='form-group'><label for='" + formField.Name + "'>" + formField.Name.toUpperCase() + "</label><input placeholder='Type in " + formField.Name + "' class='form-control' name='" + formField.Name + "' id='" + formField.Name + "' type='text' value='" + formField.Text + "' /></div>")); | |
break; | |
case "SmartCheckboxField": | |
var checked = ""; | |
if (formField.Checked === true) | |
checked = "checked"; | |
fieldset.append($("<div class='form-check'><input " + checked + " class='form-check-input' name='" + formField.Name + "' id='" + formField.Name + "' type='checkbox' /><label class='form-check-label' for='" + formField.Name + "'>" + formField.Name.toUpperCase() + "</label></div>")); | |
break; | |
case "SmartDateField": | |
fieldset.append($("<div class='form-group'><label for='" + formField.Name + "'>" + formField.Name.toUpperCase() + "</label><input class='form-control' name='" + formField.Name + "' id='" + formField.Name + "' type='date' value='" + formField.Date + "' /></div>")); | |
break; | |
case "SmartDropdownField": | |
var items; | |
formField.Items.forEach(item => { | |
if (item === formField.Text) | |
items += "<option selected>" + item + "</option>" | |
else | |
items += "<option>" + item + "</option>" | |
}); | |
fieldset.append($("<div class='form-group'><label for='" + formField.Name + "'>" + formField.Name.toUpperCase() + "</label><select class='form-control' name='" + formField.Name + "' id='" + formField.Name + "'>" + items + "</div></div>")); | |
break; | |
} | |
}); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment