2020-07-15 05:48:49 +00:00
|
|
|
// TODO: Add cleaner and less verbose solution found in formeditor.js
|
2020-05-05 04:25:56 +00:00
|
|
|
$(document).ready(function() {
|
|
|
|
$("#add").click(function() {
|
|
|
|
var lastField = $("#buildyourform div:last");
|
|
|
|
var intId = (lastField && lastField.length && lastField.data("idx") + 1) || 1;
|
|
|
|
var fieldWrapper = $("<div class=\"fieldwrapper mb-5\" id=\"field" + intId + "\"/>");
|
|
|
|
fieldWrapper.data("idx", intId);
|
2020-05-06 02:44:39 +00:00
|
|
|
var fName = $("<input name=\"fieldID" + intId + "[]\" type=\"text\" class=\"fieldname form-control\" placeholder=\"Field name...\" />");
|
|
|
|
var fType = $("<select name=\"fieldID" + 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>");
|
2020-05-05 04:25:56 +00:00
|
|
|
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();
|
|
|
|
});
|
|
|
|
fieldWrapper.append(fName);
|
|
|
|
fieldWrapper.append(fType);
|
|
|
|
fieldWrapper.append(removeButton);
|
|
|
|
$("#buildyourform").append(fieldWrapper);
|
|
|
|
});
|
|
|
|
});
|
2020-05-06 02:44:39 +00:00
|
|
|
|
|
|
|
function save() {
|
|
|
|
document.getElementById('formbuilder').submit();
|
|
|
|
}
|