Dynamic form field names

This commit is contained in:
Miguel Nogueira 2020-05-06 03:19:20 +01:00
parent 79eaa2ea54
commit dd3213e918

View File

@ -4,8 +4,8 @@ $(document).ready(function() {
var intId = (lastField && lastField.length && lastField.data("idx") + 1) || 1;
var fieldWrapper = $("<div class=\"fieldwrapper mb-5\" id=\"field" + intId + "\"/>");
fieldWrapper.data("idx", intId);
var fName = $("<input type=\"text\" class=\"fieldname form-control\" placeholder=\"Field name...\" />");
var fType = $("<select class=\"fieldtype custom-select\"><option value=\"nil\" disabled>Field type</option></option><option value=\"checkbox\">Checkbox</option><option value=\"textbox\">Textbox</option><option value=\"textarea\">Multi-line answer</option></select>");
var fName = $("<input name=\"fieldNameID" + intId + "\" type=\"text\" class=\"fieldname form-control\" placeholder=\"Field name...\" />");
var fType = $("<select name=\"fieldTypeID" + intId + "\" class=\"fieldtype custom-select\"><option value=\"nil\" disabled>Field type</option></option><option value=\"checkbox\">Checkbox</option><option value=\"textbox\">Textbox</option><option value=\"textarea\">Multi-line answer</option></select>");
var removeButton = $("<button type=\"button\" class=\"btn btn-sm btn-danger mt-3\"><i class=\"fa fa-minus\"></i></button>");
removeButton.click(function() {
$(this).parent().remove();