/*! ***************************************************************************** formstrap.js functions © 2024 by Steve Burgess This file is not redistributable and only licenced for use when using the formstrap form designer at formstrap.com ***************************************************************************** */ var sform; var field=0; var sec=0; var pagecol=0; var row=0; var formcol=0; function formaudit(silent) { offcanvasList[0].hide(); if(typeof silent=="undefined") { silent=false; } error="

Review the quality audit report below.

Click the fix button to fix each item. Remember to save your changes before running the audit again. If the highlighted issues are as you intended them to be, just click OK to dismiss the report.

"; errors=0; $("#formcontainer").find(".form-group").each(function() { key=$(this).attr("id"); keyd=key if($(this).attr("data-customid")) { keyd=keyd+" ("+$(this).attr("data-customid")+")"; } page=$(this).closest(".formpage").attr("data-page"); if($(this).attr("data-name")!="") { count=$("#formcontainer").find(".form-group[data-name=" + $(this).attr("data-name") + "]").length; } if($(this).attr("data-form")=="checkbox" || $(this).attr("data-form")=="radio") { label=$(this).find("legend").text(); if($(this).find(".checks").find("input").length==0) { error=error+``; errors++; } } else { label=$(this).find("label").text(); } if($(this).attr("data-inputgroup")=="true" && ($(this).attr("data-customclass")=="" || typeof $(this).attr("data-customclass")=="undefined")) { error=error+``; errors++; } if(label.trim()=="Label") { error=error+``; errors++; } if($(this).attr("data-name")=="" || typeof $(this).attr("data-name")=="undefined") { error=error+``; errors++; } if(count>1) { key=$(this).attr("id"); keyd=key if($(this).attr("data-customid")) { keyd=keyd+" ("+$(this).attr("data-customid")+")"; } error=error+``; errors++; } }); error=error+"
FieldLabelPageIssue
#`+keyd + ``+label+``+page+`This ` + $(this).attr("data-form") + ` field has selectable options
#`+keyd + ``+label+``+page+`This ` + $(this).attr("data-form") + ` field has been set to be a part of an input group but the group name has not been specified.
#`+keyd + ``+label+``+page+`This field seems to have the default label.
#`+keyd + ``+label+``+page+`This field does not have a name attribute. Data entered in this field will, therefore, not be submitted.
#`+keyd + ``+$(this).find("label").text()+``+page+`The name attribute (` + $(this).attr("data-name") + `) used on this field is also used on other field(s). This is not an error but may not be what you intended. This is an advisory notice.
" if(errors>0) { if(silent==false) { messagepop(error,null,null,null,null,null,null,"modal-xl"); } else { return false; } } else { if(silent==false) { messagepop("Everything looks OK

...but the audit tool won't catch all errors. Please test the form on the preview before publishing.","check-circle"); } else { return true; } } } function auditfix(type,field,page) { if(page!=document.getElementById("selectedpage").value) { gotopage(page); } $('#messageModal').modal('hide'); getcontext($('#'+field).get(0),true); if(type=="options") { setTimeout(function() { location.href="#optionstable"; },1000); setTimeout(function() { $("#optionstable").parent().parent().css("background-color","pink"); },2000); setTimeout(function() { $("#optionstable").parent().parent().css("background-color","transparent"); },8000); } if(type=="group") { setTimeout(function() { $("#fieldcontextclass").focus(); },1000); } if(type=="name") { setTimeout(function() { $("#fieldcontextname").focus(); },1000); } if(type=="label") { setTimeout(function() { $("#fieldcontextlabel").focus(); },1000); } } function getformdata(formid) { fdata={}; replicable={}; $("#"+formid).find(".form-group").each(function() { if($(this).data("name")!="") { replicableob=$(this).closest(".replicable"); replicableid=$(replicableob).attr("id"); if($(replicableob).hasClass("pagecol")) { replicablecount=$(replicableob).find(".formrowcontainer").length; replicabletype="col"; } if($(replicableob).hasClass("formrow")) { replicablecount=$(replicableob).find(".formcolcontainer").length; replicabletype="row"; } if(typeof replicableid!="undefined") { if(typeof replicable[replicableid]=="undefined") { replicable[replicableid]={}; replicable[replicableid]["groups"]=replicablecount; replicable[replicableid]["type"]=replicabletype; replicable[replicableid]["fields"]=[]; } if(replicable[replicableid]["fields"].includes($(this).data("name"))==false) { replicable[replicableid]["fields"].push($(this).data("name")); } } if(typeof fdata[$(this).data("name")]=="undefined") { if(typeof $(this).data("name")!="undefined") { fdata[$(this).data("name")]=[]; } that=this; $("#"+formid).find("[name='"+$(this).data("name") + "']").each(function() { if($(this).prop("disabled")==false && $(this).val()!="" ) { if($(that).data("form")=="checkbox" || $(that).data("form")=="radio") { fdata[$(that).data("name")].push({"Value":this.value,"Checked":this.checked,"ID":this.id,"replicable":replicableid}); } else { fdata[$(that).data("name")].push({"Value":this.value,"ID":this.id,"replicable":replicableid}); } } }); if(fdata[$(that).data("name")].length==0) { delete fdata[$(that).data("name")]; } } } }); object={"data":fdata,"replicable":replicable}; return object; } function uploadlogo(event) { event.stopPropagation(); event.preventDefault(); $("#uplogo").trigger("click"); } function doupload() { e=document.getElementById("uplogo"); var last var file = e.files[0]; e.value=null var xhr = new XMLHttpRequest(); xhr.open('post', '/scripts/uplogo.php', true); (xhr.upload || xhr).addEventListener('progress', function(e) { var done = e.position || e.loaded var total = e.totalSize || e.total; if(doneMulti Factor Authentication
Enter the 6 digit passcode from your authenticator app"); $("#email").parent().after(`
`); $("#mfacode").on("keyup",function() { $("#loginerror").html(""); this.value=this.value.trim(); if(this.value.length==6) { $("#loginbut").prop("disabled",false); } else { $("#loginbut").prop("disabled",true); } } ); $("#email").parent().remove(); $("#password").parent().remove(); $("#mfacode").focus(); $("#loginbut").html("Check Passcode"); $("#loginbut").prop("disabled",true); $("#loginerror").html(""); $("#loginbut").off("click"); $("#loginbut").removeAttr("onclick"); $("#loginbut").on("click",function() { document.getElementById("mfacode").setCustomValidity(""); if(document.getElementById("mfacode").validity.valid==false) { document.getElementById("mfacode").setCustomValidity("Enter the 6 NUMBERS from the authenticator app - ignore spaces");document.getElementById("mfacode").reportValidity(); } else { qrcheck($("#mfacode").val(),msg.hash); } }); toolovers(); $("#forgotpass").parent().parent().parent().remove(); return false; } if(msg.result=="emailFailed" || msg.result=="accountCreatedEmailFailed") { $("#loginerror").html(msg.message); $("#loginbut").parent().hide(); return false; } if(msg.result=="resetSuccess") { login(false); setTimeout(function() { $("#loginerror").html(msg.message); },500) $(but).attr("disabled",false); } if(msg.result=="resetFailed") { setTimeout(function() { $("#loginerror").html(msg.message); },500) $(but).attr("disabled",false); $(but).html("Change Password"); $("#password").val(""); $("#confirmpassword").val(""); } if(msg.result=="passwordReset") { $("#loginerror").html(msg.message); $(but).attr("disabled",false); $(but).html("Log In"); $("#loginmessage").html("Please enter your email address and password to login."); $('#password').parent().show();$('#password').attr('disabled',false); } if(msg.result=="unrecognised") { $("#loginerror").html(msg.message); $(but).attr("disabled",false); $(but).html("Log In"); $("#forgotpass").parent().show(); } if(msg.result=="accountCreated") { login(false); setTimeout(function() { $("#loginerror").html(msg.message); },500) } if(msg.result=="accountFailed") { setTimeout(function() { $("#loginerror").html(msg.message); },500) $(but).html("Register"); $(but).attr("disabled",false); } } }); } function qrcheck(passcode,hash) { if(passcode.length!=6) { return false; } $.ajax({ method:"POST", url:"/scripts/totp.php", data:{code:passcode,hash:hash}, dataType:"json" }).done(function(msg) { if(msg.response=="OK") { setTimeout(function() { location.reload(); },1000); window.open("/dashboard","dashboard"); } else { $("#loginerror").html(`

The code is incorrect or has expired

`);$("#mfacode").val("");$("#mfacode").focus(); } }); } function logout() { location.href="/logout.php"; } function login(register,id) { if(typeof id=="undefined") { id=""; } $("#messageModal").find(".modal-header").addClass("d-none"); $("#messagedia").removeClass("modal-sm modal-xl modal-md modal-lg"); $("#messagedia").addClass("modal-sm"); if(register) { if(register=="reset" && id!="") { $("#messagebod").html(`

fs

Please provide a new complex password. It needs to be at least 10 characters long and have at least 8 unique characters

`); } else { $("#messagebod").html(`

fs

Please enter your email address and specify a complex password to create a new account.

`); } } else { $("#messagebod").html(`

fs

Please enter your email address and password to login.

`); } $("#messageModal").modal("show"); $("#loginform").on("submit",function(e) { e.preventDefault(); }); $("#loginform").on("keyup",function(e) { if(e.keyCode==13) { $("#loginbut").trigger("click"); } }); } function minmaxfunction(e,attribute,fieldtype) { $("#messagebod").find("btn").off("*"); $(".modal-header").removeClass("d-none"); $(".modal-header").html(` `); $("#messagedia").removeClass("modal-sm modal-md"); $("#messagedia").addClass("modal-lg"); if(fieldtype=="date") { $("#messagebod").html(`
Set `+ attribute+` to:

Note that this will be the evaluated when the form is first loaded. To set or change the value of `+ attribute+` during form completion, use Field Events.

`); } if(fieldtype=="datetime-local") { $("#messagebod").html(`
Set `+ attribute+` to:

Note that this will be the evaluated when the form is first loaded. To set or change the value of `+ attribute+` during form completion, use Field Events.

`); } if(fieldtype=="time") { $("#messagebod").html(`
Set `+ attribute+` to:

Note that this will be the evaluated when the form is first loaded. To set or change the value of `+ attribute+` during form completion, use Field Events.

`); } $("#messageModal").modal("show"); if($(e).attr("data-"+attribute.toLowerCase()+"-formula")) { data=$(e).attr("data-"+attribute.toLowerCase()+"-formula").split("|"); $("#formulastart").val(data[0]); $("#formulaoperator").val(data[1]); $("#formulaincrement").val(data[2]); $("#formulaunit").val(data[3]); $("#customstring").val($(e).attr("data-"+attribute.toLowerCase()+"-formula-custom")); } $("#messagebod").find("input,select").on("change blur keyup",function() { $(".btn#formgo").hide(); $(".btn#formtest").show(); $("#formtestdiv").html(""); }); $("#messagebod #formulastart").on("change blur",function() { if(this.value=="custom") { $(".formulaform").hide(); $(".customstring").show(); } else { $(".formulaform").show(); $(".customstring").hide(); } $("#formtestdiv").html(""); }); $("#formulastart").trigger("change"); $("#messagebod").find(".btn#formgo").on("click",function() { saveformula(e,attribute); }); $("#messagebod").find(".btn#formtest").on("click",function() { testformula(e,attribute); }); } function testformula(e,attr) { var dispdate; months=["January","Feburary","March","April","May","June","July","August","September","October","November","December"]; if(document.getElementById("formulaoperator").value=="" || document.getElementById("formulastart").value=="" || document.getElementById("formulaincrement").value=="" || document.getElementById("formulaunit").value=="") { $("#formtestdiv").html("

Please Complete all Parts of the Formula

"); $(".btn#formgo").hide(); $(".btn#formtest").show(); return false; } if(document.getElementById("formulastart").value=="custom" && document.getElementById("customstring").value=="") { $("#formtestdiv").html("

Please enter a custom string

"); $(".btn#formgo").hide(); $(".btn#formtest").show(); return false; } string=document.getElementById("formulastart").value; if(document.getElementById("formulaoperator").value=="Plus") { string=string+" +"; } else { string=string+" -"; } string=string+"" + document.getElementById("formulaincrement").value + " " + document.getElementById("formulaunit").value; if(document.getElementById("formulastart").value=="custom") { string=document.getElementById("customstring").value; } if(strtotime(string)) { calcdate=new Date(strtotime(string)*1000); $(".btn#formgo").show(); $(".btn#formtest").hide(); } else { if(document.getElementById("formulastart").value=="custom") { $("#formtestdiv").html(`

The custom string could not be evaluated
Provide a text description of the date you wish to be used.

The custom string is evaluated using the Locutus JavaScript port of the PHP strtotime() function.
For more information on how these functions work, visit:
https://locutus.io/php/datetime/strtotime/
https://www.php.net/manual/en/function.strtotime.php

`); } else { $("#formtestdiv").html(`

The formula could not be evaluated

`); } $(".btn#formgo").hide(); $(".btn#formtest").show(); return false; } if($(e).data("form")=="date") { dispdate=calcdate.getFullYear()+"-"+str_pad(calcdate.getMonth()+1,2,"0","STR_PAD_LEFT")+"-"+str_pad(calcdate.getDate(),2,"0","STR_PAD_LEFT"); } if($(e).data("form")=="datetime-local") { dispdate=calcdate.getFullYear()+"-"+str_pad(calcdate.getMonth()+1,2,"0","STR_PAD_LEFT")+"-"+str_pad(calcdate.getDate(),2,"0","STR_PAD_LEFT")+"T"+str_pad(calcdate.getHours(),2,"0","STR_PAD_LEFT")+":"+str_pad(calcdate.getMinutes(),2,"0","STR_PAD_LEFT"); } if($(e).data("form")=="time") { dispdate=str_pad(calcdate.getHours(),2,"0","STR_PAD_LEFT")+":"+str_pad(calcdate.getMinutes(),2,"0","STR_PAD_LEFT"); } document.getElementById("customstring").value=string; $("#formtestdiv").html("

If you started the form now, the "+ attr + " attribute of the field would be set to

"); } function publish() { saveform(true); $("#popupModal").find(".modal-header").removeClass("d-none"); $("#popupModal").find(".modal-header").html(` `); offcanvasList[0].hide(); offcanvasList[1].hide(); $("#popupdia").removeClass("modal-sm modal-md modal-xl modal-xxl"); $("#popupdia").addClass("modal-lg"); $("#popupbod").css("height","auto"); $("#popupbod").css("overflow",""); $("#popupbod").html(`

managed by formstrap

Upload your form to formstrap.
formstrap will host your form and process and store all form submissions. Various options are available for you to retrieve the data.

self-hosted

Download almost everything you need for the client-side to publish the form on your own website. You just need to handle the processing of the submitted form data.

Between 1p and 17p per form per day
based on the number of active forms you have each day

Free!
you can make an optional donation on the next page

  or  

Compare


create, edit and manage multiple forms at the same timecreate one form at a time
formstrap hosts your forms at a custom URL: https://formstrap.com/yourcompany.
you can download the forms too if you want to self-host
you publish the form on your website
(client-side scripts and instructons provided)
edit live forms on the fly using the formstrap WYSIWYG editorto edit live forms you need to edit the raw html provided in the download
formstrap processes the form and stores the submitted data in our UK datacentre
even if you are self-hosting the client-side
you create your own server-side script to process submitted POST data
access to support
unlimited form submissions while forms are active
formstrap hosted forms are optionally protected from SPAM by Google reCAPTCHA v3
embedding - get a formstrap managed form with a seamless user experience
formstap can send an email confirmation to the person completing the form on successful submission
receive a PDF of the submitted form by email each time a form is submitted
log in to download the data for importing into excel, SPSS etc
analyse data using formstrap analytics
(coming soon)
`); $("#popupModal").modal("show"); } function tour() { $("#popupModal").find(".modal-header").removeClass("d-none"); $("#popupModal").find(".modal-header").html(` `); offcanvasList[0].hide(); offcanvasList[1].hide(); $("#popupdia").removeClass("modal-sm modal-md"); $("#popupdia").addClass("modal-lg"); $("#popupbod").html(``); $("#popupModal").modal("show"); $('#carouselExampleControls').carousel() } function serialiseform(save) { $("#formcontainer").find(".formpage").sort(sort_sections) // sort elements .appendTo('#formcontainer'); // append again to the list layout={}; fields={}; pagination={"Scroll":$("#formcontainer").attr("data-paginationscroll"),"Position":$("#formcontainer").attr("data-paginationposition"),"Submit":$("#formcontainer").attr("data-paginationsubmit"),"Format":$("#formcontainer").attr("data-pagination"),"Pages":$("#formcontainer").attr("data-pages")}; formcontainerclasses=getclass($("#fullformcontainer"),3); logocontainerclasses=getclass($("#formlogocontainer"),3); textcontainerclasses=getclass($("#formintrocontainer"),3); texttitleclasses=getclass($("#formtitle"),3); textdescclasses=getclass($("#formdescription"),3); heading={ "logo":{ "src":$("#formlogo").attr("src"), "alt":$("#formlogo").attr("alt"), "icon":$("#formcontainer").attr("data-favicon"), "aspect":$("#formlogo").attr("data-aspectratio"), "containerclasses":logocontainerclasses }, "text":{ "containerclasses": textcontainerclasses, "title":{ "text":$("#formtitle").html(), "classes":$("#formtitle").attr("class") }, "description":{ "renderHTML":$("#formcontainer").attr("data-renderhtml"), "text":$("#formdescription").html(), "classes": $("#formdescription").attr("class") } } }; sections=[]; seccols=[]; rows=[]; customids={}; rowcols=[]; redactions="no"; fieldorder=[]; // THE FORM $("#formcontainer").find(".formpage").each(function() { if($(this).attr("data-customid")) { customids[$(this).attr("id")]={"ID":$(this).attr("data-customid"),Type:".formpage"}; } // FIND SECTIONS (pagecols) seccols=[]; $(this).find(".pagecol").each(function() { if($(this).attr("data-customid")) { customids[$(this).attr("id")]={"ID":$(this).attr("data-customid"),Type:".pagecol"}; } // FIND ROWS (formrow) rows=[]; $(this).find(".formrow").each(function() { if($(this).attr("data-customid")) { customids[$(this).attr("id")]={"ID":$(this).attr("data-customid"),Type:".formrow"}; } // FIND COLUMNS rowcols=[]; $(this).find(".formcol").each(function() { if($(this).attr("data-customid")) { customids[$(this).attr("id")]={"ID":$(this).attr("data-customid"),Type:".formcol"}; } // FIND FIELDS fieldorder=[]; $(this).find(".form-group").each(function() { if($(this).attr("data-customid")) { customids[$(this).attr("id")]={"ID":$(this).attr("data-customid"),Type:".form-group"}; } if($(this).hasClass("otherselectgroup")==false) { fieldorder.push({"SystemID":$(this).attr("id")}); } }); classes=getclass(this,1); containerclasses=getclass(this,2); if($(this).attr("data-card")=="Yes") { $(this).find(".columncard").attr("data-colour"); rowcols.push({"SystemID":$(this).attr("id"),"CustomID":$(this).attr("data-customid"),"CustomClass":$(this).attr("data-customclass"),"Title":$(this).find(".column-header").html(),"Description":$(this).find(".column-description").html(),"DescriptionHTML":$(this).attr("data-renderhtml"),"Visible":$(this).attr("data-initiallyvisible"),"CardColour":$(this).attr("data-cardcolour"),"Flex":$(this).find("[data-auto-height=true]").length>0,"Card":$(this).attr("data-card"),"Class":classes,"ContainerClass":containerclasses,"Fields":fieldorder}); } else { rowcols.push({"SystemID":$(this).attr("id"),"CustomID":$(this).attr("data-customid"),"CustomClass":$(this).attr("data-customclass"),"Title":$(this).find(".column-header").html(),"Description":$(this).find(".column-description").html(),"Flex":$(this).find("[data-auto-height=true]").length>0,"DescriptionHTML":$(this).attr("data-renderhtml"),"Visible":$(this).attr("data-initiallyvisible"),"Class":classes,"ContainerClass":containerclasses,"Fields":fieldorder}); } }); classes=getclass(this,1); containerclasses=getclass(this,2); if($(this).attr("data-card")=="Yes") { rows.push({"SystemID":$(this).attr("id"),"CustomID":$(this).attr("data-customid"),"CustomClass":$(this).attr("data-customclass"),"Title":$(this).find(".row-header").html(),"Description":$(this).find(".row-description").html(),"DescriptionHTML":$(this).attr("data-renderhtml"),"Replicable":$(this).attr("data-replicable"),"ReplicableAdd":$(this).attr("data-replicableadd"),"ReplicableDelete":$(this).attr("data-replicabledelete"),"Visible":$(this).attr("data-initiallyvisible"),"Gutter-X":$(this).attr("data-gx"),"Gutter-Y":$(this).attr("data-gy"),"CardColour":$(this).attr("data-cardcolour"),"Flex":$(this).find("[data-auto-height=true]").length>0,"Card":$(this).attr("data-card"),"Class":classes,"ContainerClass":containerclasses,"RowColumns":rowcols}); } else { rows.push({"SystemID":$(this).attr("id"),"CustomID":$(this).attr("data-customid"),"CustomClass":$(this).attr("data-customclass"),"Title":$(this).find(".row-header").html(),"Description":$(this).find(".row-description").html(),"DescriptionHTML":$(this).attr("data-renderhtml"),"Replicable":$(this).attr("data-replicable"),"ReplicableAdd":$(this).attr("data-replicableadd"),"ReplicableDelete":$(this).attr("data-replicabledelete"),"Visible":$(this).attr("data-initiallyvisible"),"Gutter-X":$(this).attr("data-gx"),"Gutter-Y":$(this).attr("data-gy"),"Class":classes,"ContainerClass":containerclasses,"Flex":$(this).find("[data-auto-height=true]").length>0,"RowColumns":rowcols}); } }); classes=getclass(this,1); containerclasses=getclass(this,2); if($(this).attr("data-card")=="Yes") { seccols.push({"SystemID":$(this).attr("id"),"CustomID":$(this).attr("data-customid"),"CustomClass":$(this).attr("data-customclass"),"Title":$(this).find(".sectioncolumn-header").html(),"Description":$(this).find(".sectioncolumn-description").html(),"DescriptionHTML":$(this).attr("data-renderhtml"),"Visible":$(this).attr("data-initiallyvisible"),"CardColour":$(this).attr("data-cardcolour"),"Card":$(this).attr("data-card"),"Flex":$(this).find("[data-auto-height=true]").length>0,"Class":classes,"ContainerClass":containerclasses,"Rows":rows,"Replicable":$(this).attr("data-replicable"),"ReplicableAdd":$(this).attr("data-replicableadd"),"ReplicableDelete":$(this).attr("data-replicabledelete")}); } else { seccols.push({"SystemID":$(this).attr("id"),"CustomID":$(this).attr("data-customid"),"CustomClass":$(this).attr("data-customclass"),"Title":$(this).find(".sectioncolumn-header").html(),"Description":$(this).find(".sectioncolumn-description").html(),"Flex":$(this).find("[data-auto-height=true]").length>0,"DescriptionHTML":$(this).attr("data-renderhtml"),"Visible":$(this).attr("data-initiallyvisible"),"Class":classes,"ContainerClass":containerclasses,"Rows":rows,"Replicable":$(this).attr("data-replicable"),"ReplicableAdd":$(this).attr("data-replicableadd"),"ReplicableDelete":$(this).attr("data-replicabledelete")}); } }); classes=getclass(this,1); containerclasses=getclass(this,2); if($(this).attr("data-nopdf")=="yes") { redactions="yes"; } if($(this).attr("data-card")=="Yes") { sections.push({"Page":$(this).attr("data-page"),"SystemID":$(this).attr("id"),"NoPDF":$(this).attr("data-nopdf"),"CustomID":$(this).attr("data-customid"),"Visible":$(this).attr("data-initiallyvisible"),"CustomClass":$(this).attr("data-customclass"),"Flex":$(this).find("[data-auto-height=true]").length>0,"Title":$(this).find(".section-header").html(),"Description":$(this).find(".section-description").html(),"DescriptionHTML":$(this).attr("data-renderhtml"),"Gutter-X":$(this).attr("data-gx"),"Gutter-Y":$(this).attr("data-gy"),"CardColour":$(this).attr("data-cardcolour"),"Card":$(this).attr("data-card"),"Class":classes,"ContainerClass":containerclasses,"SectionColumns":seccols}); } else { sections.push({"Page":$(this).attr("data-page"),"SystemID":$(this).attr("id"),"NoPDF":$(this).attr("data-nopdf"),"CustomID":$(this).attr("data-customid"),"Visible":$(this).attr("data-initiallyvisible"),"Flex":$(this).find("[data-auto-height=true]").length>0,"CustomClass":$(this).attr("data-customclass"),"Title":$(this).find(".section-header").html(),"Description":$(this).find(".section-description").html(),"DescriptionHTML":$(this).attr("data-renderhtml"),"Class":classes,"ContainerClass":containerclasses,"Gutter-X":$(this).attr("data-gx"),"Gutter-Y":$(this).attr("data-gy"),"SectionColumns":seccols}); } } ); layout["Form"]={"hasRedactions":redactions,"ID":$("#formcontainer").attr("data-id"),"Name":$("#formcontainer").attr("data-name"),"SaveToLocal":$("#formcontainer").attr("data-localsave"),"SaveOpt": $("#formcontainer").attr("data-localsaveopt"),"TextColour":$("#formcontainer").attr("data-textcolour"),"Colour":$("#formcontainer").attr("data-colour"),"Class":formcontainerclasses,"Sections":sections,"Heading":heading,"Pagination":pagination,"POSTURL":$("#formcontainer").attr("data-posturl"),"SuccessURL":$("#formcontainer").attr("data-successurl"),"FailureURL":$("#formcontainer").attr("data-failureurl"),"reCAPTCHA":$("#formcontainer").attr("data-recaptchakey")}; fieldgroups={}; x=0; $("#formcontainer").find(".form-group").each(function() { if($(this).hasClass("otherselectgroup")==false) { b=$(this); c=$(this).attr("id"); classes=getclass(this,1); containerclasses=getclass(this,2) fields[c]={}; fields[c]["Order"]=x; fields[c]["Parent"]=b.closest(".formcol").attr("id"); fields[c]["Type"]=b.attr("data-form"); fields[c]["Attributes"]={}; if(b.closest("[data-replicable=yes]").length>0) { fields[c]["Attributes"]["replicablegroup"]=b.closest("[data-replicable=yes]").attr("id"); fields[c]["Attributes"]["replicablegroupname"]=b.closest("[data-replicable=yes]").attr("data-replicablename"); } fields[c]["Attributes"]["required"]=b.attr("data-required"); fields[c]["Attributes"]["readonly"]=b.attr("data-readonly"); fields[c]["Attributes"]["disabled"]=b.attr("data-disabled"); fields[c]["Attributes"]["donotdisable"]=b.attr("data-enabled-on-hide"); if( b.attr("data-form")=="checkbox" || b.attr("data-form")=="radio") { fields[c]["Attributes"]["twocols"]=b.attr("data-twocols"); } if(b.attr("data-form")=="textarea") { fields[c]["Attributes"]["autoheight"]=b.attr("data-auto-height"); fields[c]["Attributes"]["height"]=b.attr("data-height-numeric"); } fields[c]["Attributes"]["sendmail"]=b.attr("data-sendmail"); fields[c]["Attributes"]["html"]=b.attr("data-html"); fields[c]["Attributes"]["visible"]=b.attr("data-initiallyvisible"); if(b.attr("data-form")=="select" || b.attr("data-form")=="checkbox" || b.attr("data-form")=="radio") { fields[c]["Attributes"]["otherspecify"]=b.attr("data-other-specify"); } fields[c]["Attributes"]["customid"]=b.attr("data-customid"); fields[c]["Attributes"]["customclass"]=b.attr("data-customclass"); if(b.attr("data-customclass")!="" && typeof b.attr("data-customclass")!="undefined") { if(typeof fieldgroups["."+b.attr("data-customclass")]=="undefined") { fieldgroups["."+b.attr("data-customclass")]=[]; } fieldgroups["."+b.attr("data-customclass")].push(b.attr("id")); } fields[c]["Attributes"]["floatinglabel"]=b.attr("data-floatinglabel"); fields[c]["Attributes"]["autocomplete"]=b.attr("data-autocomplete"); fields[c]["Attributes"]["defaultvalue"]=b.attr("data-defaultvalue"); fields[c]["Attributes"]["minformula"]=b.attr("data-min-formula"); fields[c]["Attributes"]["mincustomformula"]=b.attr("data-min-formula-custom"); fields[c]["Attributes"]["min"]=b.find("input").eq(0).attr("min"); fields[c]["Attributes"]["max"]=b.find("input").eq(0).attr("max"); fields[c]["Attributes"]["step"]=b.find("input").eq(0).attr("step"); fields[c]["Attributes"]["minlength"]=b.find("input,textarea").eq(0).attr("minlength"); fields[c]["Attributes"]["maxlength"]=b.find("input,textarea").eq(0).attr("maxlength"); fields[c]["Attributes"]["class"]=classes; fields[c]["Attributes"]["maxformula"]=b.attr("data-max-formula"); fields[c]["Attributes"]["maxcustomformula"]=b.attr("data-max-formula-custom"); fields[c]["Attributes"]["defaultformula"]=b.attr("data-default-formula"); fields[c]["Attributes"]["defaultcustomformula"]=b.attr("data-default-formula-custom"); fields[c]["Attributes"]["name"]=b.attr("data-name"); fields[c]["Attributes"]["inputid"]=b.find("input,select,textarea").eq(0).attr("id"); fields[c]["Attributes"]["inputsize"]=b.attr("data-input-size"); fields[c]["Attributes"]["prepend"]=b.attr("data-prepend"); fields[c]["Attributes"]["append"]=b.attr("data-append"); fields[c]["Attributes"]["inputgroup"]=b.attr("data-inputgroup"); if(b.attr("data-form")=="checkbox" || b.attr("data-form")=="radio") { fields[c]["Attributes"]["inputid"]=b.attr("id")+"-options"; fields[c]["Legend"]=b.find("legend").find(".labeltext").eq(0).html(); fields[c]["Options"]=[]; b.find(".checks").find(".form-check").each(function() { fields[c]["Options"].push({"Value":$(this).find("input").val(),"Label":$(this).find("label").html()}); }); } else { if(b.attr("data-form")=="select") { fields[c]["Options"]=[]; b.find("select").eq(0).find("option").each(function() { fields[c]["Options"].push({"Value":$(this).val(),"Label":$(this).html()}); }); } else { fields[c]["Attributes"]["placeholder"]=b.find("input,textarea").eq(0).attr("placeholder"); fields[c]["Attributes"]["pattern"]=b.find("input,select,textarea").eq(0).attr("pattern"); } fields[c]["Label"]=b.find("label").find(".labeltext").html(); } fields[c]["Note"]=b.attr("data-note"); fields[c]["NotePosition"]=b.attr("data-note-position"); fields[c]["CustomValidation"]={}; fields[c]["CustomValidation"]["Required"]=b.find("input,select,textarea").eq(0).attr("data-required"); fields[c]["CustomValidation"]["RangeOver"]=b.find("input,select,textarea").eq(0).attr("data-rangeover"); fields[c]["CustomValidation"]["RangeUnder"]=b.find("input,select,textarea").eq(0).attr("data-rangeunder"); fields[c]["CustomValidation"]["TooLong"]=b.find("input,select,textarea").eq(0).attr("data-toolong"); fields[c]["CustomValidation"]["TooShort"]=b.find("input,select,textarea").eq(0).attr("data-tooshort"); fields[c]["CustomValidation"]["TypeMismatch"]=b.find("input,select,textarea").eq(0).attr("data-mismatch"); fields[c]["CustomValidation"]["StepMismatch"]=b.find("input,select,textarea").eq(0).attr("data-stepmismatch"); fields[c]["CustomValidation"]["Pattern"]=b.find("input,select,textarea").eq(0).attr("data-pattern"); fields[c]["CustomValidation"]["CustomEvent"]=b.find("input,select,textarea").eq(0).attr("data-customevent"); } x++; }); form={}; form["layout"]=layout; form["fields"]=fields; form["fieldgroups"]=fieldgroups; form["events"]=JSON.parse(localStorage.getItem("events")); form["customids"]=customids; return form; } function fieldcontext(e) { $("#fieldcontextbody").find(".all").show(); $("#fieldcontextbody").find("div." + $(e).data("form")).show(); $("#fieldcontextbody").find("i." + $(e).data("form")).show(); if($(e).data("form")=="checkbox" || $(e).data("form")=="radio" || $(e).data("form")=="range" || $(e).data("form")=="select") { $("#fieldcontextplaceholder").parent().hide(); $("#fieldcontextplaceholder").val(""); } else { $("#fieldcontextplaceholder").parent().show(); } if($(e).data("form")=="checkbox" || $(e).data("form")=="radio" || $(e).data("form")=="range" || $(e).hasClass("form-floating")) { $("#fieldcontextsize").parent().hide(); $("#fieldcontextsize").val(""); } else { $("#fieldcontextsize").parent().show(); } if($(e).data("form")=="range" || $(e).data("form")=="select") { $("#fieldcontextreadonly").parent().parent().hide(); $("#fieldcontextreadonly").prop("checked",false); } else { $("#fieldcontextreadonly").parent().parent().show(); } if($(e).data("form")=="number" || $(e).data("form")=="range" || $(e).data("form")=="date" || $(e).data("form")=="time" || $(e).data("form")=="datetime-local") { $("#fieldcontextmin").parent().parent().show(); $("#fieldcontextrangeunderalert").parent().parent().show(); $("#fieldcontextrangeoveralert").parent().parent().show(); } else { $("#fieldcontextmin").parent().parent().hide(); if($(e).data("form")!="checkbox" && $(e).data("form")!="radio" && $(e).data("form")!="select" || $(e).data("form")!="range") $("#fieldcontextrangeunderalert").parent().parent().hide(); $("#fieldcontextrangeoveralert").parent().parent().hide(); } if($(e).data("form")=="text" || $(e).data("form")=="date" || $(e).data("form")=="email" || $(e).data("form")=="tel" || $(e).data("form")=="url" || $(e).data("form")=="password" || $(e).data("form")=="textarea") { if($(e).data("form")!="date") { $("#fieldcontextminlength").parent().parent().show(); $("#fieldcontextmaxlength").parent().parent().show(); $("#fieldcontexttoolongalert").parent().parent().show(); $("#fieldcontexttooshortalert").parent().parent().show(); } else { $("#fieldcontextminlength").parent().parent().hide(); $("#fieldcontextmaxlength").parent().parent().hide(); $("#fieldcontexttoolongalert").parent().parent().hide(); $("#fieldcontexttooshortalert").parent().parent().hide(); } if($(e).data("form")=="email" || $(e).data("form")=="url") { $("#fieldcontextmismatchalert").parent().parent().show(); } else { $("#fieldcontextmismatchalert").parent().parent().hide(); } if($(e).data("form")!="textarea") { $("#fieldcontextpattern").parent().parent().show(); $("#fieldcontextpatternalert").parent().parent().show(); } else { $("#fieldcontextpattern").parent().parent().hide(); $("#fieldcontextpatternalert").parent().parent().hide(); } } else { $("#fieldcontextminlength").parent().parent().hide(); $("#fieldcontextmaxlength").parent().parent().hide(); $("#fieldcontextpattern").parent().parent().hide(); $("#fieldcontextpatternalert").parent().parent().hide(); $("#fieldcontextrangeunderalert").parent().parent().hide(); $("#fieldcontextrangeoveralert").parent().parent().hide(); $("#fieldcontextmismatchalert").parent().parent().hide(); } if($(e).data("form")=="number" || $(e).data("form")=="range" || $(e).data("form")=="date" || $(e).data("form")=="time" || $(e).data("form")=="datetime-local") { $("#fieldcontextmin").parent().parent().show(); $("#fieldcontextrangeunderalert").parent().parent().show(); $("#fieldcontextrangeoveralert").parent().parent().show(); } else { $("#fieldcontextmin").parent().parent().hide(); if($(e).data("form")!="checkbox" && $(e).data("form")!="radio" && $(e).data("form")!="select" || $(e).data("form")!="range") $("#fieldcontextrangeunderalert").parent().parent().hide(); $("#fieldcontextrangeoveralert").parent().parent().hide(); } $(".fa-function").hide(); $(".fa-calendar-days").hide(); $("#fieldcontext").show(); if($(e).data("form")=="date" || $(e).data("form")=="datetime-local" || $(e).data("form")=="time") { if($(e).attr("data-default-formula")!="" && typeof $(e).attr("data-default-formula")!="undefined") { $("#fieldcontextbody #fieldcontextdefault").hide(); $("#fieldcontextbody #fieldcontextdefault").siblings(".btn").show(); $("#fieldcontextbody #fieldcontextdefault").siblings("label").find("i.fa-function").hide(); $("#fieldcontextbody #fieldcontextdefault").siblings("label").find("i.fa-calendar-days").show(); } else { $("#fieldcontextbody #fieldcontextdefault").show(); $("#fieldcontextbody #fieldcontextdefault").siblings(".btn").hide(); $("#fieldcontextbody #fieldcontextdefault").siblings("label").find("i.fa-function").show(); $("#fieldcontextbody #fieldcontextdefault").siblings("label").find("i.fa-calendar-days").hide(); } if($(e).attr("data-min-formula")!="" && typeof $(e).attr("data-min-formula")!="undefined") { $("#fieldcontextbody #fieldcontextmin").hide(); $("#fieldcontextbody #fieldcontextmin").siblings(".btn").show(); $("#fieldcontextbody #fieldcontextmin").siblings("label").find("i.fa-function").hide(); $("#fieldcontextbody #fieldcontextmin").siblings("label").find("i.fa-calendar-days").show(); } else { $("#fieldcontextbody #fieldcontextmin").show(); $("#fieldcontextbody #fieldcontextmin").siblings(".btn").hide(); $("#fieldcontextbody #fieldcontextmin").siblings("label").find("i.fa-function").show(); $("#fieldcontextbody #fieldcontextmin").siblings("label").find("i.fa-calendar-days").hide(); } if($(e).attr("data-max-formula")!="" && typeof $(e).attr("data-max-formula")!="undefined") { $("#fieldcontextbody #fieldcontextmax").hide(); $("#fieldcontextbody #fieldcontextmax").siblings(".btn").show(); $("#fieldcontextbody #fieldcontextmax").siblings("label").find("i.fa-function").hide(); $("#fieldcontextbody #fieldcontextmax").siblings("label").find("i.fa-calendar-days").show(); } else { $("#fieldcontextbody #fieldcontextmax").show(); $("#fieldcontextbody #fieldcontextmax").siblings(".btn").hide(); $("#fieldcontextbody #fieldcontextmax").siblings("label").find("i.fa-function").show(); $("#fieldcontextbody #fieldcontextmax").siblings("label").find("i.fa-calendar-days").hide(); } } } function getcsv() { $("#messagedia").removeClass("modal-sm"); $("#messagedia").addClass("modal-md"); $("#messagebod").html("

Paste or enter a 2 column, tab-delimited list below. The first column is the value that will be submitted. The second is the descriptive label.

If you are entering the list manually, the tab key functionality has been changed to allow tabs to be input. To move to the next field using the keyboard, press the tab key twice in succession.

You can also choose from lists created by formstrap or other users.

"); $("#messageModal").modal("show"); $("#csvinput").off(); $("#csvinput").on("keydown",function(e) { if(e.keyCode==9 || e.which==9) { e.preventDefault(); last=this.value.substring(this.selectionStart-1,this.selectionStart); if(last=="\t") { this.value=this.value.replace(/\t$/gm,""); $("#clearlist").focus(); return false; } var s = this.selectionStart; this.value = this.value.substring(0,this.selectionStart) + "\t" + this.value.substring(this.selectionEnd); this.selectionEnd = s+1; } }); $("#csvinput").on("keyup",function(e) { if(e.keyCode==9 || e.which==9) { max=0; lines=this.value.split("\n"); if(lines.length>1) { $.each(lines,function(a,b) { first=b.split("\t"); if(first[0].length>max) { max=first[0].length; } }); this.style.tabSize=max+2; this.style.fontFamily="Courier New"; } } }); $.ajax({ method:"POST", url:"/getlists.php" }).done(function(msg) { $("#presclists").html(msg); }) } function savelist() { $.ajax({ method:"POST", url:"/savelist.php", data:{list:document.getElementById("csvinput").value,label:document.getElementById("fieldcontextlabel").value} }).done(function(msg) { if(msg=="OK") { $("#savebut").hide(); $("#savenote").html("

Thank you. Your list has been saved. It will be reviewed before being made available to others.

"); } }) } function getlist(list) { $("#csvinput").html(""); if(list) { $.ajax({ method:"POST", data:{id:list}, dataType:"json", url:"/getlist.php" }).done(function(msg) { if(msg.response=="OK") { $("#csvinput").val(msg.list); document.getElementById("csvinput").style.tabSize=parseInt(msg.firstcol)+2; $("#csvinput").css("font-family","Courier"); } else { messagepop("The list could not be retrieved","bug"); } }) } } function processcsv() { csv=document.getElementById("csvinput").value; csv=csv.split("\n"); cnt=$("#fieldcontextoptions").find(".descriptor").length; added=0;j=0; html=""; for(i=0;i  `; j++; } } if(document.getElementById("clearlist").checked) { $("#fieldcontextoptions").html(html); } else { $("#fieldcontextoptions").append(html); } j=0; for(i=0;i`; var page; var css = ""; max = 0; options[1] = ``; $("[data-page]").each(function() { page = parseInt($(this).attr("data-page")); if (page == $("[data-page]").length && $("#formcontainer").attr("data-pagination") == "numbers") { css = "rightradius" } else { css = "" } htmlpage[page] = `
  • ` + page + `
  • `; if (page > max) { max = page } next = max + 1 }); $("#formcontainer").attr("data-pages",max); if (next > 0) { for (i = 1; i <= next; i++) { if (htmlpage[i]) { htmllist = htmllist + htmlpage[i] } options[i] = ``; optionsselect = optionsselect + options[i] } html = html.replace("#PAGES#", htmllist); $("#formcontextpaginationcontainer").hide(); if(next==2) { html = ``; } if (next > 0) { $("#fullform").find(".formpage").hide(); $("#fullform").find(".formpage[data-page='" + document.getElementById("selectedpage").value + "']").show(); $("#formcontextpaginationcontainer").show(); if (document.getElementById("formcontextpaginationposition").value.substring(0, 3) == "top" || document.getElementById("formcontextpaginationposition").value.substring(0, 4) == "both") { $(html).insertBefore("#formcontainer") } if (document.getElementById("formcontextpaginationposition").value.substring(0, 4) == "bott" || document.getElementById("formcontextpaginationposition").value.substring(0, 4) == "both") { $(html).insertAfter("#formcontainer") } if (document.getElementById("formcontextpagination").value == "numbers") { $("#fullform").find(".page-next").remove(); $(".page-previous").remove(); $("#fullform").find(".page-number").removeClass("d-sm-inline"); $("#fullform").find(".page-number").removeClass("d-none") } if (document.getElementById("formcontextpagination").value == "prevnext") { $("#fullform").find(".page-number").removeClass("d-sm-inline") } if (document.getElementById("formcontextpagination").value == "next") { $("#fullform").find(".page-number").removeClass("d-sm-inline"); $("#fullform").find(".page-previous").remove(); $("#fullform").find(".page-next a").addClass("fullradius"); $("#fullform").find(".page-next a").removeClass("rightradius") } if (document.getElementById("selectedpage").value == 1) { $("#fullform").find(".page-previous").addClass("disabled") } $("#fullform").find(".page-item").removeClass("active"); $("#fullform").find(".pagenum" + document.getElementById("selectedpage").value).addClass("active") } document.getElementById("sectioncontextpage").innerHTML = optionsselect; if (document.getElementById("formcontextpaginationposition").value.substring(document.getElementById("formcontextpaginationposition").value.length - 1) == "t") { $("#fullform").find(".formpagenav").find("ul").addClass("justify-content-start"); $("#fullform").find(".formpagenav").addClass("text-start"); } if (document.getElementById("formcontextpaginationposition").value.substring(document.getElementById("formcontextpaginationposition").value.length - 1) == "d") { $("#fullform").find(".formpagenav").find("ul").addClass("justify-content-end"); $("#fullform").find(".formpagenav").addClass("text-end"); } if (document.getElementById("formcontextpaginationposition").value.substring(document.getElementById("formcontextpaginationposition").value.length - 1) == "e") { $("#fullform").find(".formpagenav").find("ul").addClass("justify-content-center"); $("#fullform").find(".formpagenav").addClass("text-center"); } } if(typeof g!="undefined") { gotopage(g); } } function prevpage() { if ($("#fullform").find(".page-item.active").prev().hasClass("page-number")) { $("#fullform").find(".page-item.active").prev().trigger("click") } } function nextpage() { if ($("#fullform").find(".page-item.active").next().hasClass("page-number")) { $("#fullform").find(".page-item.active").next().trigger("click") } } function gotopage(page,uns) { if($("[data-page="+page+"]").length==0) { return false; } if(typeof uns=="undefined") { uns=true; } if(uns) { unselect(); } offcanvasList[0].hide(); document.getElementById("selectedpage").value = page; $("#fullform").find(".page-next").removeClass("disabled"); $("#fullform").find(".page-previous").removeClass("disabled"); $("#fullform").find(".formpage").hide(); $("#fullform").find(".formpage[data-page='" + page + "']").show(); $(".page-item").removeClass("active"); $("#fullform").find(".pagenum" + page).addClass("active"); if ($("#fullform").find(".pagenum" + page).next().hasClass("page-next")) { $("#fullform").find(".page-next").addClass("disabled"); $("#fullform").find(".submitbutton").removeClass("d-none") } else { if (getstorage("paginationsubmit") == "last") { $("#fullform").find(".submitbutton").addClass("d-none") } } if ($("#fullform").find(".pagenum" + page).prev().hasClass("page-previous")) { $("#fullform").find(".page-previous").addClass("disabled") } } function toggleoffcanvas() { if (localStorage.getItem("saveto") == "session") { $(".offcanvascontextarrow").toggle(); if ($('#offcanvascontext').hasClass('offcanvas-start')) { sessionStorage.setItem('offcanvas', 'end'); offcanvasList[0].hide(); setTimeout(function() { $('#offcanvascontext').removeClass('offcanvas-start'); $('#offcanvascontext').addClass('offcanvas-end') }, 400); setTimeout(function() { offcanvasList[0].show() }, 700) } else { sessionStorage.setItem('offcanvas', 'start'); offcanvasList[0].hide(); setTimeout(function() { $('#offcanvascontext').removeClass('offcanvas-end'); $('#offcanvascontext').addClass('offcanvas-start') }, 400); setTimeout(function() { offcanvasList[0].show() }, 700) } } else { $(".offcanvasarrow").toggle(); if ($('#offcanvascontext').hasClass('offcanvas-start')) { localStorage.setItem('offcanvas', 'end'); offcanvasList[0].hide(); setTimeout(function() { $('#offcanvascontext').removeClass('offcanvas-start'); $('#offcanvascontext').addClass('offcanvas-end') }, 400); setTimeout(function() { offcanvasList[0].show() }, 700) } else { localStorage.setItem('offcanvas', 'start'); offcanvasList[0].hide(); setTimeout(function() { $('#offcanvascontext').removeClass('offcanvas-end'); $('#offcanvascontext').addClass('offcanvas-start') }, 400); setTimeout(function() { offcanvasList[0].show() }, 700) } } } function presubmitvalidity(formid,justcheck,posturl) { var success={}; var failure={}; if (typeof justcheck=="undefined") { justcheck=false } formvalid=true; $("#"+formid +" input,#" +formid+" select,#" +formid+" textarea").each(function(index) { if(this.disabled==false) { if($(this).data("valid")==false) { if($(this).data("custom ")) { this.setCustomValidity($(this).data("customevent")); } else { this.setCustomValidity("Your response to this field is not valid"); } } else { this.setCustomValidity("") } if(this.validity.valid==false) { if(this.validity.valueMissing) { if($(this).data("required")) { this.setCustomValidity($(this).data("required")); } else { this.setCustomValidity("You must complete this part of the form"); } } if(this.validity.rangeUnderflow) { if($(this).data("rangeunder")) { this.setCustomValidity($(this).data("rangeunder")); } else { this.setCustomValidity("The value entered is too low"); } } if(this.validity.rangeOverflow) { if($(this).data("rangeover")) { this.setCustomValidity($(this).data("rangeover")); } else { this.setCustomValidity("The value entered is too high"); } } if(this.validity.tooShort) { if($(this).data("tooshort")) { this.setCustomValidity($(this).data("tooshort")); } else { this.setCustomValidity("Your response is too short."); } } if(this.validity.tooLong) { if($(this).data("toolong")) { this.setCustomValidity($(this).data("toolong")); } else { this.setCustomValidity("Your response is too long."); } } if(this.validity.stepMismatch) { if($(this).data("stepmismatch")) { this.setCustomValidity($(this).data("stepmismatch")); } else { this.setCustomValidity("The value you have entered doesn't comply with the required step interval."); } } if(this.validity.typeMismatch) { if($(this).data("typemismatch")) { this.setCustomValidity($(this).data("typemismatch")); } else { this.setCustomValidity("The value you have entered doesn't match the input type requested"); } } if(this.validity.patternMismatch) { if($(this).data("pattern")) { this.setCustomValidity($(this).data("pattern")); } else { this.setCustomValidity("The information you have provided does not match the required format."); } } formvalid=false that=this that.reportValidity(); return false; } } } ) if(formvalid && justcheck==false) { $.ajax({ method:"post", url:posturl, data:{formid:formid,record:document.getElementById(formid+"-record").value,data:getformdata(formid)}, dataType:"json" }).done(function(msg) { if(msg.response=="OK") { $("#"+formid+"-dirty").val(""); if(typeof formsuccess!="undefined") { if(typeof formsuccess[formid.replace("fsform-","")]=="function") { formsuccess[formid.replace("fsform-","")](); } else { $("#"+formid).find(".formcontainer").html(`



    The form was successfully submitted

    `); $("#"+formid).find(".formpagenav").remove(); localStorage.removeItem(formid+"-data"); } } else { $("#"+formid).find(".formcontainer").html(`



    The form was successfully submitted

    `); $("#"+formid).find(".formpagenav").remove(); localStorage.removeItem(formid+"-data"); } } else { if(typeof formfailure!="undefined") { if(typeof formfailure[formid.replace("fsform-","")]=="function") { formfailure[formid.replace("fsform-","")](); } else { if(msg.error) { messagepop(msg.error,msg.icon); } else { messagepop("The form submission failed.

    Please try again later.","circle-xmark"); } } } else { if(msg.error) { messagepop(msg.error,msg.icon); } else { messagepop("The form submission failed.

    Please try again later.","circle-xmark"); } } } }); return false; } if(formvalid) { return true; } else { return false; } } function initialiseform(formid,posturl,json) { if(typeof userevents[formid]=="function") { userevents[formid](); } // ADD EVENT TO SUBMIT BUTTON TO INVOKE CUSTOM FORM VALIDATION $("#"+formid).find(".submitbutton").on("click",function(){ presubmitvalidity(formid,false,posturl); return false; }); // RESET PAGINATION AND SHOW PAGE 1 $("#"+formid).find(".formcontainer").find(".formpage").hide(); if(document.getElementById(formid+"-selectedpage")) { $("#"+formid).find(".formcontainer").find(".formpage.visibleyes[data-page='" +document.getElementById(formid+"-selectedpage").value +"']").show(); gotopage(formid,1,true); } toolovers(); $("#formcontainer").find(".formpage").sort(sort_sections) .appendTo("#formcontainer"); $("#"+formid).find(".formcontainer").find("[data-min-formula-custom]").each(function() { if($(this).data("min-formula-custom")!="") { $(this).find("input").attr("min",date($(this).data("min-formula-custom"),$(this).data("form"))); } }); $("#"+formid).find(".formcontainer").find("[data-max-formula-custom]").each(function() { if($(this).data("max-formula-custom")!="") { $(this).find("input").attr("max",date($(this).data("max-formula-custom"),$(this).data("form"))); } }); $("#"+formid).find(".formcontainer").find("[data-default-formula-custom]").each(function() { if($(this).data("default-formula-custom")!="") { $(this).find("input").attr("value",date($(this).data("default-formula-custom"),$(this).data("form"))); } }); } function reporterror(e) { messagepop("

    There has been an error:
    "+e.error.message+"

    ","bug",function() { submiterror(); },function() { return false; },"Submit","Cancel",null,"modal-md"); } function submiterror() { html=""; json=""; if($("#errorincludedata").attr("checked")=="checked") { html=localStorage.getItem("formstrap"); json=localStorage.getItem("formstrapjson"); } $.ajax({ url:"/scripts/reportjserror.php", method:"POST", data:{realm:"editor",email:document.getElementById("erroruseremail").value,error:document.getElementById("errorstack").value,useraction:document.getElementById("erroruseraction").value,html:html,json:json}, dataType:"json" }).done(function(msg) { if(msg.response=="OK") { messagepop("Thank you for helping us to identify and fix formstrap errors","thumbs-up"); } else { messagepop("The error could not be reported","bug"); } }); } function toggleFullscreen(e) { let elem = document.querySelector('body'); if (!document.fullscreenElement) { elem.requestFullscreen().catch(err=>{ alert(`Error attempting to enable full-screen mode:${err.message}(${err.name})`) } ); $(e).find("i").removeClass("fa-expand-wide"); $(e).find("i").addClass("fa-compress-wide"); } else { document.exitFullscreen(); $(e).find("i").addClass("fa-expand-wide"); $(e).find("i").removeClass("fa-compress-wide"); } } var beforeUnloadHandler; $(document).ready(function() { window.addEventListener("keyup",function(e) { if($("#fullform").is(":visible")==false) { return false; } if(e.code=="KeyF" && e.altKey && e.ctrlKey) { formsettings(); } if(e.code=="KeyS" && e.altKey && e.ctrlKey) { saveform(); } if(e.code=="KeyP" && e.altKey && e.ctrlKey) { preview(); } if(document.getElementById("selectedcomponent").value && $("#offcanvascontext").hasClass("show")==false) { if($("#"+document.getElementById("selectedcomponent").value).hasClass("form-group")) { container="fieldcontainer"; context="field"; desc="Field"; } if($("#"+document.getElementById("selectedcomponent").value).hasClass("pagecol")) { container="pagecolcontainer"; context="sectioncolumn"; desc="Section Column"; } if($("#"+document.getElementById("selectedcomponent").value).hasClass("formrow")) { container="formrowcontainer"; context="row"; desc="Row"; } if($("#"+document.getElementById("selectedcomponent").value ).hasClass("formcol")) { container="formcolcontainer"; context="column"; desc="Column"; } if(e.code=="KeyX" && e.altKey && e.ctrlKey) { deletecomponent($("#"+document.getElementById("selectedcomponent").value ) ,context,desc); } if(e.code=="KeyM" && e.altKey && e.ctrlKey) { offcanvasList[0].show(); } if(e.code=="KeyC" && e.altKey && e.ctrlKey) { clone($("#"+document.getElementById("selectedcomponent").value )); } if(e.code=="ArrowUp" && e.altKey && e.ctrlKey) { p=$("#"+document.getElementById("selectedcomponent").value).index(); if(p==0 ) { element=$("#"+document.getElementById("selectedcomponent").value) currentcontainer=$("#"+document.getElementById("selectedcomponent").value).closest("."+container); elems=$("#formcontainer").find("."+container); previous= elems.eq(elems.index(currentcontainer) -1); if($(previous).hasClass(container) && elems.index(currentcontainer)>0) { $(previous).append(element); gotopage($(previous).closest(".formpage").attr("data-page"),false); element.get(0).scrollIntoView(true); } } if(p>0) { previous=$("#"+document.getElementById("selectedcomponent").value).prev(); $("#"+document.getElementById("selectedcomponent").value).after(previous); } dirty(); } if(e.code=="ArrowDown" && e.altKey && e.ctrlKey) { p=$("#"+document.getElementById("selectedcomponent").value).index(); t=$("#"+document.getElementById("selectedcomponent").value).siblings().length; if(p==t ) { element=$("#"+document.getElementById("selectedcomponent").value) currentcontainer=$("#"+document.getElementById("selectedcomponent").value).closest("."+container); elems=$("#formcontainer").find("."+container); next= elems.eq(elems.index(currentcontainer) +1); if($(next).hasClass(container)) { $(next).prepend(element); gotopage($(next).closest(".formpage").attr("data-page"),false); element.get(0).scrollIntoView(true); } } if(p>=0 && p { // Recommended event.preventDefault(); // Included for legacy support, e.g. Chrome/Edge < 119 event.returnValue = true; }; if (localStorage.getItem("offcanvas")) { $("#offcanvascontext").removeClass("offcanvas-end"); $("#offcanvascontext").removeClass("offcanvas-start"); $("#offcanvascontext").addClass("offcanvas-" + localStorage.getItem("offcanvas")); if (localStorage.getItem("offcanvas") == "end") { $("#offcanvasarrowright").hide() } else { $("#offcanvasarrowleft").hide() } } else { $("#offcanvascontext").removeClass("offcanvas-end"); $("#offcanvascontext").removeClass("offcanvas-start"); $("#offcanvascontext").addClass("offcanvas-end"); $("#offcanvasarrowright").hide() } $(".savenote").toggle(); if (localStorage.getItem("formstrap")) { json=JSON.parse(localStorage.getItem("formstrapjson")); if(typeof json=="undefined" || json==null) { json={}; } if(typeof json["events"]!="undefined") { events=json["events"]; } else { events={}; } localStorage.setItem("events",JSON.stringify(events)); $("#home").addClass("d-none"); $("#fullform").html(localStorage.getItem("formstrap")); $("#fullform").removeClass("d-none"); pagesort(); setTimeout(function() { propagate(true) }, 500) } else { $("#home").removeClass("d-none"); localStorage.removeItem("events"); runsortable(); } if(localStorage.getItem("storagewarned")==null) { privacypop(); } countpages(); toolovers(); gotopage(1); field=$("#formcontainer").attr("data-field"); sec=$("#formcontainer").attr("data-sec"); pagecol=$("#formcontainer").attr("data-pagecol"); row=$("#formcontainer").attr("data-row"); formcol=$("#formcontainer").attr("data-formcol"); if($("#formcontainer").attr("data-favicon")) { $("#favicon").attr("href",$("#formcontainer").attr("data-favicon")); } if($("#formcontainer").attr("data-colour")) { $("body").css("background-color",$("#formcontainer").attr("data-colour")); } if($("#formcontainer").attr("data-textcolour")) { $("#fullform").css("color",$("#formcontainer").attr("data-textcolour")); } unselect(); if($("#formcontainer").is(":visible")) { $(".start").toggle(); } checksession(); if(location.hash=="#About") { aboutpop(); } $("#context").on("scroll",function() { if(this.scrollTop<50) { $("#goup").addClass("d-none"); } else { if($("#goup").is(":visible")==false) { $("#goup").removeClass("d-none"); } } }); }); var offcanvasElementList = [].slice.call(document.querySelectorAll('.offcanvas')); var offcanvasList = offcanvasElementList.map(function(offcanvasEl) { return new bootstrap.Offcanvas(offcanvasEl) }); spelled = false; function preview() { saveform(); $.ajax({ url: "save.php", method: "POST", data: { structure: JSON.stringify(serialiseform()) } }).done(function(msg) { window.open("/preview","formstrappreview"); }) } function aboutpop() { messagepop(`

    About Formstrap

    As a jobbing, self-taught developer who worked in the public and third sectors for longer than I care to mention, I developed a lot of bespoke browser-based, database-driven systems (e.g. client records systems, personnel management systems, intranets etc).

    These systems often required many forms so I developed a rudimentary, browser based editor to help me create, modify and deploy these forms quickly.

    When I decided to give up the 9-to-5, I thought others may find such a system useful. formstrap was conceived. The idea has been completely reworked from scratch using Bootstrap 5.3, jQuery and jQuery-UI, PHP and MySQL. The editor mostly runs on the client (the earlier version made lots of server calls) so is quick and has a low impact on metered connections.

    formstrap has no financial, legal or any other connection with Bootstrap. I just love the library and have been building browser-based applications using it for years.

    I hope you find formstrap useful. I would welcome your constructive feedback, comments, suggestions for developments and, of course, donations are always gratefully received if you want to support my work .

    Steve @ SPBCodes

    `,`info-circle`,null,null,null,null,null,"modal-md",null,"green"); location.href="#popupmessage"; } function getfeedbackform() { messagepop(`Please complete the form shown below
    `,`comments`,function() { if(cf) { clearInterval(cf); } return false;},null,`Cancel`,null,null,`modal-md`,null,`blue`,null,`danger`); cf=setInterval(function() { $.ajax({ url:"/scripts/checkfeedback.php", method:"POST", }).done(function(msg) { if(msg=="OK") { clearInterval(cf); setTimeout(function() { $("#messageModal").modal("hide"); $("#messagebod").html(""); },5000); } }) },5000); } function privacypop() { messagepop(`

    Cookie and Privacy Policy

    This site uses an essential, first-party session cookie to maintain your session if and when you create an account and log in. A session cookie is also used when you preview your form to allow the preview page to access your form metadata without having to store it in the formstrap database. This information is immediately discarded from the server-side once the preview page is loaded.

    No third party cookies are used.

    The site uses your browser's local storage to store the form and its settings while you are using the editor. Data is also stored here to indicate you have clicked "OK" on this privacy policy; and also when you click to agree to the Terms of Use. By proceeding, you agree that the formstrap website can access, edit and delete formstrap data saved in your browser's local storage. Please note that formstrap cannot access local storage used by other websites.

    The form design data saved in local storage is only sent in full to the formstrap server (UK datacentre) when you publish or preview the form. Once the self-host package or preview is completed, the data is discarded. When creating events, a server-side "helper" function is used but the data that is sent to it is not retained.

    `,"cookie-bite",function () { localStorage.setItem("storagewarned",new Date()); $("#messageModal").modal("hide"); },null,"I Agree",null,null,"modal-md",null,"green"); location.href="#popupmessage"; } function tandcpop() { messagepop(`

    Terms of Use

    The formstrap "self-host" free service is offered "as-is" and is intended to be a helpful tool. It is offered with no warranty or guarantee of support.

    By using this service you agree to indemnify formstrap and its owner against any negative outcome arising from the use a form you have created using the free "self-host" service.

    You may use the formstrap editor as you wish - but your use must be fair and proportionate. The owner of formstrap reserves the right to withdraw the service if your use of the service has excessive or negative impact on the formstrap server(s) or other users.

    The code and scripts that are provided when you download the self-hosting package are free from viruses, tracking scripts* or malicious code when they are delivered to you. Once you have the code you could modify it. Doing this might break the form or cause it to behave in a way not anticipated or intended by formstrap.

    The form scripts provided do not contain advertising or promotional material except for a link at the bottom of the rendered form stating "made by formstrap" with a link to the formstrap website. You MAY remove this link if you wish by editing the index.html file in the package. Some of the scripts in the package are from third parties. The licence and copyright notices in these documents MUST be left intact when you publish the package on your own website. The readme.pdf document in the package provides more information about this.

    "Self-hosted" forms are not saved to the formstrap servers. As such, it will not be possible for formstrap to recover your work if, for example, you delete the formstrap local storage from your device's browser. It is also not be possible for formstrap to assist you in transferring your work from one device to another. If you wish to do this please sign up for an account. Separate Terms of Use apply to account holders. You will be asked to agree to these terms if you decide to create an account.

    * if you enable Google reCAPTCHA on your form then Google may store data or cookies on the devices of form users in order to provide the reCAPTCHA service.

    `,`signature`,function () { localStorage.setItem("selfhosttandc",new Date()); $("#messageModal").modal("hide"); },function () { localStorage.removeItem("selfhosttandc"); $("#messageModal").modal("hide"); },"I Agree","I Don't Agree",null,"modal-xl",null,"green"); location.href="#popupmessage"; } function help() { if(document.getElementById("mainlogout")) { messagepop(`
    Keyboard Shortcuts
    Ctrl Alt F to edit form settings
    Ctrl Alt S to save form changes
    Ctrl Alt P to preview form

    Click an element and then:
    Ctrl Alt to move it up
    Ctrl Alt to move it down
    Ctrl Alt M to view its metadata
    Ctrl Alt X to delete it
    Ctrl Alt C to clone it
    Tooltips and More Support

    You can get some help from the Tooltips in the metadata forms for each component type.

    You can also view the sample forms in the editor.

    `,null,function () { $("#offcanvascontext").find("i.fa-info-circle").removeClass("fa-bounce"); },null,"Cancel",null,null,"modal-lg",null,"green",null,"danger",null,null,null,function() { if(localStorage.getItem("formstrap")==null) { $("#ticketsenddata").parent().hide(); } $("#messageYes").parent().parent().prepend(`
    `); $("#submitticket").off("*"); } ); $("#offcanvascontext").find("i.fa-info-circle").addClass("fa-bounce"); location.href="#popupmessage"; } else { $("#offcanvascontext").find("i.fa-info-circle").addClass("fa-bounce"); messagepop(`
    Keyboard Shortcuts
    Ctrl Alt F to edit form settings
    Ctrl Alt S to save form changes
    Ctrl Alt P to preview form

    Click an element and then:
    Ctrl Alt to move it up
    Ctrl Alt to move it down
    Ctrl Alt M to view its metadata
    Ctrl Alt X to delete it
    Ctrl Alt C to clone it
    Tooltips

    You can get some help from the tooltips in the metadata forms for each component type.

    You can also view the sample forms in the editor.

    To view the metadata form, use your mouse to invoke the context menu (e.g. right button click) on the component you want to edit - or tap and hold on touch devices.

    Registered users can submit support tickets.

    `,null,function() { $("#offcanvascontext").find("i.fa-info-circle").removeClass("fa-bounce"); offcanvasList[0].hide();login(true) ; },function () { $("i.fa-info-circle").removeClass("fa-bounce"); },"Register","Close",null,"modal-lg",null,"green"); location.href="#popupmessage"; } } var conhtml; var actionhtml; var newee function dosavetemplate(e,context,f) { event.preventDefault(); jsone={}; document.getElementById("templatename").setCustomValidity(""); if(f.checkValidity()==false) { if(document.getElementById("templatename").validity.valueMissing) { document.getElementById("templatename").setCustomValidity("Please provide a name for the template"); } if(document.getElementById("templatename").validity.tooShort) { document.getElementById("templatename").setCustomValidity("The template name should be at least 10 characters long"); } if(document.getElementById("templatename").validity.tooLong) { document.getElementById("templatename").setCustomValidity("The template name should a maximum of 150 characters long"); } if(document.getElementById("templatename").validity.patternMismatch) { document.getElementById("templatename").setCustomValidity("Please use only letters, numbers and spaces."); } f.reportValidity(); return false; } var lookup={}; lookup["sectioncolumn"]="Section Column"; lookup["form"]="Form"; lookup["row"]="Row"; lookup["section"]="Section"; lookup["column"]="Column"; var sec,seccol,row,col,field; field=$(e).closest(".form-group"); col=$(e).closest(".formcol"); prevcol=$(e).closest(".formcol").prevAll().length; row=$(e).closest(".formrow"); prevrow=$(e).closest(".formrow").prevAll().length; seccol=$(e).closest(".pagecol"); prevseccol=$(e).closest(".pagecol").prevAll().length; sec=$(e).closest(".formpage"); prevsec=$(e).closest(".formpage").prevAll().length; json=serialiseform(); if(context=="column") { jsone={"layout": { "Form": { "Sections": [{"SectionColumns": [{"Rows": [{"RowColumns": [json["layout"]["Form"]["Sections"][prevsec]["SectionColumns"][prevseccol]["Rows"][prevrow]["RowColumns"][prevcol]] }] }] }] } },"fields":json["fields"],"events":json["events"] } jsone["fields"]=json["fields"]; } else { if(context=="row") { jsone={"layout": { "Form": { "Sections": [{"SectionColumns": [{"Rows":[json["layout"]["Form"]["Sections"][prevsec]["SectionColumns"][prevseccol]["Rows"][prevrow]] }] }] } },"fields":json["fields"],"events":json["events"] } } else { if(context=="sectioncolumn") { jsone={"layout": { "Form": { "Sections": [{"SectionColumns":[json["layout"]["Form"]["Sections"][prevsec]["SectionColumns"][prevseccol]] }] } },"fields":json["fields"],"events":json["events"] } } else { if(context=="section") { jsone={"layout": { "Form": { "Sections":[json["layout"]["Form"]["Sections"][prevsec]["SectionColumns"][prevseccol]] } } ,"fields":json["fields"],"events":json["events"] } } else { if(context="form") { jsone=json; } } } } } var post=$(f).serializeArray(); post.push({name:"HTML",value:$(e).prop("outerHTML")}); post.push({name:"Context",value:context}); post.push({name:"JSON",value:JSON.stringify(jsone)}); $.ajax({ url:"/scripts/savetemplate.php", method:"POST", data:post, dataType:"json" }).done(function(msg) { if(msg.response=="OK") { $('#messageModal').modal('hide'); setTimeout(function() { messagepop("Your template has been saved.","circle-check"); },1000); } else { if(msg.response=="dup") { document.getElementById("templatename").setCustomValidity("This template name has already been used"); f.reportValidity(); return false; } else { $("#templatesaveerror").html(msg.response); } } }).fail(function(e) { $("#templatesaveerror").html("There has been a fatal server error. The template could not be saved.

    Please Try again Later"); }); } function savetemplate(e,context) { if($("#mainlogout").length>0) { lookup={}; lookup["sectioncolumn"]="Section Column"; lookup["form"]="Form"; lookup["row"]="Row"; lookup["section"]="Section"; lookup["column"]="Column"; offcanvasList[0].hide(); messagepop(`

    Save `+lookup[context]+` as a Template

    `,"save",function() { return false; },null,"Cancel",null,null,null,null,null,null,"danger"); $("#messageYes").parent().before("
    "); $("#savetemplate").on("click",function() { dosavetemplate(e,context,document.getElementById("template"));}); } else { offcanvasList[0].hide(); messagepop(`Only logged in users can create templates.

    Please register or login first`,`circle-xmark`); } } function dosavetemplateold(e,context,f) { event.preventDefault(); document.getElementById("templatename").setCustomValidity(""); if(f.checkValidity()==false) { if(document.getElementById("templatename").validity.valueMissing) { document.getElementById("templatename").setCustomValidity("Please provide a name for the template"); } if(document.getElementById("templatename").validity.tooShort) { document.getElementById("templatename").setCustomValidity("The template name should be at least 10 characters long"); } if(document.getElementById("templatename").validity.tooLong) { document.getElementById("templatename").setCustomValidity("The template name should a maximum of 150 characters long"); } if(document.getElementById("templatename").validity.patternMismatch) { document.getElementById("templatename").setCustomValidity("Please use only letters, numbers and spaces."); } f.reportValidity(); return false; } var post=$(f).serializeArray(); post.push({name:"HTML",value:$(e).prop("outerHTML")}); post.push({name:"Context",value:context}); $.ajax({ url:"/scripts/savetemplate.php", method:"POST", data:post, dataType:"json" }).done(function(msg) { if(msg.response=="OK") { $('#messageModal').modal('hide'); setTimeout(function() { messagepop("Your template has been saved.","circle-check"); },1000); } else { if(msg.response=="dup") { document.getElementById("templatename").setCustomValidity("This template name has already been used"); f.reportValidity(); return false; } else { $("#templatesaveerror").html(msg.response); } } }).fail(function(e) { $("#templatesaveerror").html("There has been a fatal server error. The template could not be saved.

    Please Try again Later"); }); } function viewtemplates(e,context) { offcanvasList[0].hide(); $.ajax({ method:"POST", data:{context:context}, url:"/scripts/gettemplates.php", dataType:"json" }).done(function(msg) { if(msg.response=="OK") { $("#popupcon").find(".modal-header").removeClass("d-none"); $("#popupcon").find(".modal-title").html(`Choose a template Add to FORM `); $("#popupdia").removeClass("modal-sm modal-md modal-lg modal-xl modal-xxl"); $("#popupdia").addClass("modal-xl"); $("#popupbod").html(msg.html); $("#carouselExampleControls").find("input,select,textarea").attr("disabled",true); $("#carouselExampleControls").find("a").off(); $("#carouselExampleControls").find("a").attr("onclick",""); $("#templatebutton").on("click",function() { usetemplate(e,context,$("#carouselExampleControls").find(".active").attr("id"));}); toolovers(); $("#popupbod").css("height","75vh"); $("#popupbod").css("overflow","auto"); $("#popupModal").modal("show"); $('.carousel').carousel(); } else { messagepop(msg.error,"circle-exclamation"); } }); } function usetemplate(e,context,templateid) { $.ajax({ method:"POST", url:"/scripts/gettemplate.php", data:{id:templateid,context:context}, dataType:"json" } ).done(function(msg) { $("#popupModal").modal("hide"); if(msg.response=="OK") { unselect(); $(e).find(".subcontainer").eq(0).append(msg.html); newe=$(e).find(".subcontainer").eq(0).children().last(); newe=$(newe).find("div[id]").addBack(); renumbertemplate(newe,msg.json.events,msg.html); } }); } function clone(e) { unselect(); newee=e; $(e).after($(e).prop("outerHTML")); newe=$(e).next(); cloned=$(newe).find("div[id]").addBack(); renumber(cloned,e); } function renumbertemplate(template,events,html) { types={}; oldids={}; types["form-group"]=parseInt($("#formcontainer").attr("data-field")); types["formpage"]=parseInt($("#formcontainer").attr("data-sec")); types["pagecol"]=parseInt($("#formcontainer").attr("data-pagecol")); types["formrow"]=parseInt($("#formcontainer").attr("data-row")); types["formcol"]=parseInt($("#formcontainer").attr("data-formcol")); $.each(events,function(a,b) { console.log(a); console.log($(html)); if($(html).find(a).length==0 && $(html).find("[data-customclass='"+a.replace(".","") + "']").length==0) { delete events[a]; } }); $(template).each(function() { $(this).removeAttr("data-customid"); if($(this).hasClass("form-group")) { oid=$(this).attr("id"); types["form-group"]++; oldids["#"+$(this).attr("id")]="#field"+types["form-group"]; $(this).attr("id","field"+types["form-group"]); $(this).find("textarea,select,input").eq(0).attr("id","input-field"+types["form-group"]); $(this).find("label").eq(0).attr("for","input-field"+types["form-group"]); o=0; $(this).find(".checks").find(".form-check").each(function() { $(this).find("input").attr("id","option-"+o+"-field"+types["form-group"]); $(this).find("label").attr("for","option-"+o+"-field"+types["form-group"]); o++; }); } if($(this).hasClass("formpage")) { types["formpage"]++; oldids["#"+$(this).attr("id")]="#section"+types["formpage"]; $(this).attr("id","section"+types["formpage"]); $(this).find("div.sectioncard").eq(0).attr("id","cardsection"+types["formpage"]); } if($(this).hasClass("pagecol")) { types["pagecol"]++; oldids["#"+$(this).attr("id")]="#sectioncol"+types["pagecol"]; $(this).attr("id","sectioncol"+types["pagecol"]); $(this).find("div.sectioncolumncard").eq(0).attr("id","cardpagecol"+types["pagecol"]); } if($(this).hasClass("formrow")) { types["formrow"]++; oldids["#"+$(this).attr("id")]="#formrow"+types["formrow"]; $(this).attr("id","formrow"+types["formrow"]); $(this).find("div.rowcard").eq(0).attr("id","cardformrow"+types["formrow"]); } if($(this).hasClass("formcol")) { types["formcol"]++; oldids["#"+$(this).attr("id")]="#formcol"+types["formcol"]; $(this).attr("id","formcol"+types["formcol"]); $(this).find("div.columncard").eq(0).attr("id","cardformcol"+types["formcol"]); } }); $("#formcontainer").attr("data-field",types["form-group"]); $("#formcontainer").attr("data-sec",types["formpage"]); $("#formcontainer").attr("data-pagecol",types["pagecol"]); $("#formcontainer").attr("data-row",types["formrow"]); $("#formcontainer").attr("data-formcol",types["formcol"]); json=serialiseform(); if(json["events"]) { events=Object.assign(events,json["events"]); } eventstext=replaceAll(JSON.stringify(events),oldids) localStorage.setItem("events",(eventstext)); propagate(false,template); dirty(); } function renumber(cloned,e) { var json=serialiseform(); if(typeof newevents=="undefined") { var newevents={}; } if(json["events"]) { var events=json["events"]; } else { events={}; } var oid; var replace={}; var types={}; types["form-group"]=parseInt($("#formcontainer").attr("data-field")); types["formpage"]=parseInt($("#formcontainer").attr("data-sec")); types["pagecol"]=parseInt($("#formcontainer").attr("data-pagecol")); types["formrow"]=parseInt($("#formcontainer").attr("data-row")); types["formcol"]=parseInt($("#formcontainer").attr("data-formcol")); $(cloned).each(function() { $(this).removeAttr("data-customid"); if($(this).hasClass("form-group")) { oid=$(this).attr("id"); types["form-group"]++; $(this).attr("id","field"+types["form-group"]); $(this).find("textarea,select,input").eq(0).attr("id","input-field"+types["form-group"]); $(this).find("label").eq(0).attr("for","input-field"+types["form-group"]); o=0; $(this).find(".checks").find(".form-check").each(function() { $(this).find("input").attr("id","option-"+o+"-field"+types["form-group"]); $(this).find("label").attr("for","option-"+o+"-field"+types["form-group"]); o++; }); if(json["events"]) { if(json["events"]["#"+oid]) { replace["#"+oid]="#field"+types["form-group"]; newevents["#field"+types["form-group"]]=json["events"]["#"+oid]; } } } if($(this).hasClass("formpage")) { types["formpage"]++; $(this).attr("id","section"+types["formpage"]); $(this).find("div.sectioncard").eq(0).attr("id","cardsection"+types["formpage"]); } if($(this).hasClass("pagecol")) { types["pagecol"]++; $(this).attr("id","sectioncol"+types["pagecol"]); $(this).find("div.sectioncolumncard").eq(0).attr("id","cardpagecol"+types["pagecol"]); } if($(this).hasClass("formrow")) { types["formrow"]++; $(this).attr("id","formrow"+types["formrow"]); $(this).find("div.rowcard").eq(0).attr("id","cardformrow"+types["formrow"]); } if($(this).hasClass("formcol")) { types["formcol"]++; $(this).attr("id","formcol"+types["formcol"]); $(this).find("div.columncard").eq(0).attr("id","cardformcol"+types["formcol"]); } }); if($(newevents).length>0) { newevents=JSON.stringify(newevents); newevents=replaceAll(newevents,replace); newevents=JSON.parse(newevents); events=Object.assign(events,newevents); localStorage.setItem("events",JSON.stringify(events)); } $("#formcontainer").attr("data-field",types["form-group"]); $("#formcontainer").attr("data-sec",types["formpage"]); $("#formcontainer").attr("data-pagecol",types["pagecol"]); $("#formcontainer").attr("data-row",types["formrow"]); $("#formcontainer").attr("data-formcol",types["formcol"]); propagate(false,e); dirty(); } function replaceAll(string, replaceObj) { return Object.keys(replaceObj).reduce( (f, s, i) => `${f}`.replace(new RegExp(s, 'ig'), replaceObj[s]), string ) } function normalise(e) { // if($(e).hasClass("form-group")) { $(e).attr("id",e.id); $(e).find("textarea,select,input").eq(0).attr("id","input-"+e.id); $(e).find("label").eq(0).attr("for","input-"+e.id); o=0; $(e).find(".checks").find(".form-check").each(function() { $(this).find("input").attr("id","option-"+o+"-"+e.id); $(this).find("label").attr("for","option-"+o+"-"+e.id); o++; }); } if($(e).hasClass("formpage")) { $(e).attr("id",e.id) $(e).find("div.sectioncard").eq(0).attr("id","card"+e.id); } if($(e).hasClass("pagecol")) { $(e).attr("id",e.id); $(e).find("div.sectioncolumncard").eq(0).attr("id","card"+e.id); } if($(e).hasClass("formrow")) { $(e).attr("id",e.id); $(e).find("div.rowcard").eq(0).attr("id","card"+e.id); } if($(e).hasClass("formcol")) { $(e).attr("id",e.id) $(e).find("div.columncard").eq(0).attr("id","card"+e.id); } $(e).removeAttr("data-id"); } function ticket() { document.getElementById("ticketsubject").setCustomValidity(""); $("#offcanvascontext").find("i.fa-info-circle").addClass("fa-bounce"); if(document.getElementById("checksession").value!="OK") { document.getElementById("ticketsubject").setCustomValidity("You are not logged in. Only logged in users may submit tickets."); document.getElementById("ticketsubject").reportValidity(); return false; } if(document.getElementById("ticketsubject").validity.valid==false) { document.getElementById("ticketsubject").setCustomValidity("Please provide more information about the problem. The more info we have the more quickly we can help."); document.getElementById("ticketsubject").reportValidity(); return false; } ticketdetail=document.getElementById("ticketsubject").value; html=""; json=""; if($("#ticketsenddata").attr("checked")=="checked" && localStorage.getItem("formstrap")!=null) { html=localStorage.getItem("formstrap"); json=localStorage.getItem("formstrapjson"); } $.ajax({ method:"POST", url:"/scripts/saveticket.php", data:{ticket:ticketdetail,html:html,json:json}, dataType:"json" }).done(function(msg) { if(msg.response=="OK") { $("#messageModal").modal("hide"); setTimeout(function() { messagepop("Thank you for submitting a ticket.

    Please check your email for confirmation and further information.

    You can also view the status of the ticket in your dashboard.","ticket",null,null,null,null,null,null,null,"green"); } ,500); } else { $("#ticketerror").html("

    Your ticket could not be submitted

    "+msg["error"] + "

    "); $("#submitticket").parent().remove(); } }); } function eventmeta(e) { offcanvasList[0].hide(); $(".conditions").html(""); offcanvasList[1].show(); if($(e).attr("data-customclass")=="" || typeof $(e).attr("data-customclass")=="undefined") { $("#eventtrigger").find("select").trigger("change"); } } function getevents(e) { offcanvasList[0].hide(); formdata=serialiseform(); events=JSON.parse(localStorage.getItem("events")); if(events=="" || events==null || typeof events=="undefined") { events={}; } $.ajax({ data:{formdata:JSON.stringify(formdata),id:e,events:JSON.stringify(events[e])}, method:"POST", url:"/events.php" }).done(function(msg) { msg=msg.split("||||"); $(".conditions").html(msg[0]); conhtml=msg[1]; actionhtml=msg[2]; offcanvasList[1].show(); $(".conditions").sortable( { "axis":"y", "stop":function() { saveevents(this); } }); $(".actions").sortable({ "axis":"y", "stop":function() { saveevents(this); } }); toolovers(); }); } var json; function editevent(e,type) { action=$(e).parent().parent().find("select.action").val(); subject=$(e).parent().parent().find("select.subject").val(); attribute=$(e).parent().parent().find("select.attrlist").val(); attrvals=$(e).parent().parent().find("select.attrvals").val(); attrbool=$(e).parent().parent().find("select.attrboolean").val(); attrval=$(e).parent().parent().find("select.attrvalue").val(); $(e).parent().parent().find(".attrvals").hide(); if(type=="action") { $(e).parent().parent().find(".subject").val(""); $(e).parent().parent().find(".subject").find("optgroup").removeClass("d-none"); $(e).parent().parent().find(".subject").parent().show(); } if(type=="action" && action=="delete") { $(e).closest("div.action").remove(); saveevents(e); return false; } if(action=="show" || action=="hide") { $(e).parent().parent().find(".subject").find("optgroup").removeClass("d-none"); $(e).parent().parent().find(".subject").find("optgroup.pages").addClass("d-none"); $(e).parent().parent().find(".custfunc").parent().hide(); $(e).parent().parent().find(".custfunc").val(""); } if(action=='goto' && type=="action") { $(e).parent().parent().find(".subject").val(""); $(e).parent().parent().find(".attrlist").val(""); $(e).parent().parent().find(".attrlist").parent().hide(); $(e).parent().parent().find(".attrrvalue").val(""); $(e).parent().parent().find(".attrvalue").parent().hide(); $(e).parent().parent().find(".attrboolean").val(""); $(e).parent().parent().find(".attrboolean").parent().hide(); $(e).parent().parent().find(".attrvaltype").val(""); $(e).parent().parent().find(".attrvaltype").parent().hide(); $(e).parent().parent().find(".custfunc").parent().hide(); $(e).parent().parent().find(".custfunc").val(""); $(e).parent().parent().find(".subject").find("optgroup").addClass("d-none"); $(e).parent().parent().find(".subject").find("optgroup.pages").removeClass("d-none"); } if(action=="stop" || action=="" || action=="continue" || action=="reportvalidity") { $(e).parent().parent().find(".attrpanel").hide(); $(e).parent().parent().find(".subject").parent().hide(); $(e).parent().parent().find(".custfunc").parent().hide(); $(e).parent().parent().find(".custfunc").val(""); saveevents(e); return false; } if(action=="function") { $(e).parent().parent().find(".attrpanel").hide(); $(e).parent().parent().find(".custfunc").parent().show(); $(e).parent().parent().find(".subject").parent().hide(); saveevents(e); return false; } if(action=="changeattr") { $(e).parent().parent().find(".subject").find("optgroup").addClass("d-none"); $(e).parent().parent().find(".subject").find("optgroup.fields").removeClass("d-none"); $(e).parent().parent().find(".attrpanel").show(); $(e).parent().parent().find(".custfunc").parent().hide(); $(e).parent().parent().find(".custfunc").val(""); $(e).parent().parent().find(".subject").parent().show(); if(type=="action") { $(e).parent().parent().find(".subject").val(""); $(e).parent().parent().find(".attrlist").val(""); $(e).parent().parent().find(".attrlist").parent().hide(); $(e).parent().parent().find(".attrrvalue").val(""); $(e).parent().parent().find(".attrvalue").parent().hide(); $(e).parent().parent().find(".attrboolean").val(""); $(e).parent().parent().find(".attrboolean").parent().hide(); $(e).parent().parent().find(".attrvaltype").val(""); $(e).parent().parent().find(".attrvaltype").parent().hide(); } if(type=="subject") { $(e).parent().parent().find(".attrvaltype").find("option.all").hide(); $(e).parent().parent().find(".attrvaltype").find("option."+$(subject).data("form")).show(); $(e).parent().parent().find(".attrlist").val(""); if(subject=="") { $(e).parent().parent().find(".attrpanel").hide(); } else { $(e).parent().parent().find(".attrpanel").show(); $(e).parent().parent().find(".attrlist").parent().show(); $(e).parent().parent().find("select.attrlist").find(".all").removeClass("d-none"); $(e).parent().parent().find("select.attrlist").find(".not-"+$(subject).data("form")).addClass("d-none"); } } if(type=="attribute") { if(attribute=="") { $(e).parent().parent().find(".attrvals").hide(); } else { if(attribute=="disabled" || attribute=="readonly" || attribute=="customvalid" || attribute=="required") { $(e).parent().parent().find(".attrboolean").show(); if(attribute=="customvalid") { $(e).parent().parent().find(".attrboolean").find("option[value=null]").show(); } else { $(e).parent().parent().find(".attrboolean").find("option[value=null]").hide(); } } else { if(attribute=="value" || attribute=="max" || attribute=="min") { $(e).parent().parent().find(".attrvaltype").show(); $(e).parent().parent().find(".attrvaltype").val(""); $(e).parent().parent().find(".attrvalue").hide(); $(e).parent().parent().find("input.attrvalue").attr("type",$(subject).find("input").attr("type")); } else { if(attribute!="") { $(e).parent().parent().find(".attrvaltype").hide(); $(e).parent().parent().find(".attrvaltype").val(""); $(e).parent().parent().find(".attrvalue").show(); if(attribute=="max" || attribute=="min") { $(e).parent().parent().find("input.attrvalue").attr("type",$(subject).find("input").attr("type")); } else { $(e).parent().parent().find("input.attrvalue").attr("type","number"); } } } } } } } saveevents(e,true); } function actionvalid(e) { if($(e).find("select.action").eq(0).val()=="") { return false; } if($(e).find("select.action").eq(0).val()=="stop" || $(e).find("select.action").eq(0).val()=="continue" || $(e).find("select.action").eq(0).val()=="reportvalidity" ) { return true; } if($(e).find("select.action").eq(0).val()=="function") { var r=new RegExp(/^[a-zA-Z_]+$/); if(r.test($(e).find("input.custfunc").val())==false || $(e).find("input.custfunc").val().trim()=="" || $(e).find("input.custfunc").get(0).validity.valid==false) { return false; } else { if(localStorage.getItem("custfuncwarn")!="do not warn") { if(typeof window[$(e).find("input.custfunc").val().trim()]!="function") { messagepop("The custom function specified does not exist in the current context.

    You need to write this function.

    If you are self-hosting you can edit the functions in your /js/events.js file in the package download.

    If you are hosting on formstrap, add it to the On Load JavaScript field in Form Settings in the dashboard.","exclamation-circle",function() { return false },function() { localStorage.setItem("custfuncwarn","do not warn"); return false; },"OK
    I Understand","Don't Show This Warning Again"); }; } return true; } } if($(e).find("select.subject").eq(0).val()=="") { return false; } if($(e).find("select.action").eq(0).val()=="changeattr") { if($(e).find("select.attrlist").eq(0).val()=="") { return false; } if(($(e).find("select.attrlist").eq(0).val()=="maxlength" || $(e).find("select.attrlist").eq(0).val()=="minlength" || $(e).find("select.attrlist").eq(0).val()=="step" ) && $(e).find("input.attrvalue").eq(0).val()=="") { return false; } if(($(e).find("select.attrlist").eq(0).val()=="disabled" || $(e).find("select.attrlist").eq(0).val()=="customvalid" || $(e).find("select.attrlist").eq(0).val()=="readonly" || $(e).find("select.attrlist").eq(0).val()=="required" ) && $(e).find("select.attrboolean").eq(0).val()=="") { return false; } if($(e).find("select.attrlist").eq(0).val()=="value" && $(e).find("select.attrvaltype").eq(0).val()=="") { return false; } if($(e).find("select.attrvaltype").is(":visible") && $(e).find("select.attrvaltype").val()=="") { return false; } } return true; } function eventvalid(e) { if($(e).find(".object").eq(0).val()=="") { return false; } if( $(e).find(".compare").eq(0).val()=="" && $(e).find(".object").eq(0).val()!="DO" && $(e).find(".object").eq(0).val()!="customfunc" && $(e).find(".object").eq(0).val()!="customfuncfalse") { return false; } if(($(e).find(".object").eq(0).val()=="customfunc" || $(e).find(".object").eq(0).val()=="customfuncfalse") && $(e).find(".custfuncname").eq(0).val()!="" && $(e).find(".custfuncname").get(0).validity.valid==true) { if(localStorage.getItem("custfuncwarn")!="do not warn") { if(typeof window[$(e).find(".custfuncname").val().trim()]!="function") { messagepop("The custom function specified does not exist in the current context.

    You need to write this function.

    If you are self-hosting you can edit the functions in your /js/events.js file in the package download.

    If you are hosting on formstrap, add it to the On Load JavaScript field in Form Settings in the dashboard.","exclamation-circle",function() { return false },function() { localStorage.setItem("custfuncwarn","do not warn"); return false; },"OK
    I Understand","Don't Show This Warning Again"); }; } return true; } if(($(e).find(".object").eq(0).val()=="customfunc" || $(e).find(".object").eq(0).val()=="customfuncfalse") && ($(e).find(".custfuncname").eq(0).val()=="" || $(e).find(".custfuncname").get(0).validity.valid==false)) { return false; } if( ($(e).find(".compare").eq(0).val()=="=" || $(e).find(".compare").eq(0).val()=="!=" || $(e).find(".compare").eq(0).val()=="contains" || $(e).find(".compare").eq(0).val()=="notcontains" || $(e).find(".compare").eq(0).val()==">" || $(e).find(".compare").eq(0).val()==">=" || $(e).find(".compare").eq(0).val()=="<" || $(e).find(".compare").eq(0).val()=="<=") && $(e).find("input.value").eq(0).attr("type")!="checkbox" && ($(e).find("input.value").eq(0).val()=="" && $(e).find("select.fieldvalue").eq(0).val()=="fixed")) { return false; } if(($(e).find(".compare").eq(0).val()=="=" || $(e).find(".compare").eq(0).val()=="any" || $(e).find(".compare").eq(0).val()=="all" || $(e).find(".compare").eq(0).val()=="none" || $(e).find(".compare").eq(0).val()=="!=" || $(e).find(".compare").eq(0).val()=="contains" || $(e).find(".compare").eq(0).val()=="notcontains" || $(e).find(".compare").eq(0).val()==">" || $(e).find(".compare").eq(0).val()==">=" || $(e).find(".compare").eq(0).val()=="<" || $(e).find(".compare").eq(0).val()=="<=") && $(e).find("input.value").eq(0).attr("type")=="checkbox" && $(e).find("input.value:checked").length==0) { return false; } if(($(e).find(".compare").eq(0).val()=="between" || $(e).find(".compare").eq(0).val()=="betweenx" || $(e).find(".compare").eq(0).val()=="betweenx-i" || $(e).find(".compare").eq(0).val()=="between-i" )) { if($(e).find("select[name=fieldfrom]").val()=="" || $(e).find("select[name=fieldto]").val()=="") { return false; } if($(e).find("select[name=fieldfrom]").val()=="fixed" && $(e).find("input[name=valuefrom]").val()=="") { return false; } if($(e).find("select[name=fieldto]").val()=="fixed" && $(e).find("input[name=valueto]").val()=="") { return false; } } return true; } var events; var ce; function saveevents(e,save) { if(typeof save=="undefined") { save=false; } events=[]; nosave=false; if(localStorage.getItem("events")==null || localStorage.getItem("events")=="null") { eventjson={}; } else { eventjson=JSON.parse(localStorage.getItem("events")); } z=0; a=0; $(".condition").each(function() { $(this).find(".error").html(""); if(eventvalid(this)) { events[z]={}; value=[]; $(this).find("input.value,select.value").each(function() { if(this.type=="checkbox" ) { value.push({[$(this).attr("name")]:this.value,"checked":this.checked}); } else { value.push({[$(this).attr("name")]:this.value}); } }) events[z]["Condition"]={"customfunction":$(this).find(".custfuncname").eq(0).val(),"object":$(this).find(".object").eq(0).val(),"compare":$(this).find(".compare").eq(0).val(),"fieldvalue":$(this).find(".fieldvalue").eq(0).val(),"value":value}; events[z]["Actions"]=[]; $(this).find("div.action").each(function() { $(this).find(".actionerror").html(""); if(actionvalid(this)) { events[z]["Actions"].push({"action":$(this).find("select.action").val(),"customfunction":$(this).find("input.custfunc").val(),"subject":$(this).find("select.subject").val(),"attribute":$(this).find("select.attrlist").val(),"attrvaluetype":$(this).find(".attrvaltype").val(),"attrvalueboolean":$(this).find(".attrboolean").val(),"attributevalue":$(this).find(".attrvalue").val()}); } else { $(this).find(".actionerror").html("
    This action is not valid. It will not be saved.
    "); nosave=true; } }); z++; } else { $(this).find(".error").html("
    This condition is not valid. It will not be saved.
    "); nosave=true; } }); if(events) { eventjson[document.getElementById("eventid").value]=events; } localStorage.setItem("events",JSON.stringify(eventjson)); $(".conditions").sortable( { "axis":"y", "stop":function() { saveevents(this); } }); $(".actions").sortable({ "axis":"y", "stop":function() { saveevents(this); } }); dirty(); } function geteventvalue(e,justcompare) { if(typeof justcompare=="undefined") { justcompare=false; } if(e.value=="delete") { $(e).closest(".condition").remove(); saveevents(e); return false; } if(e.value=="customfunc" || e.value=="customfuncfalse") { $(e).closest(".condition").find(".value").hide(); $(e).closest(".condition").find(".compare").hide(); $(e).closest(".condition").find(".custfunccont").show(); saveevents(e); return false; } $(e).closest(".condition").find(".custfunccont").hide(); $(e).closest(".condition").find(".value").hide(); $(e).closest(".condition").find(".compare").hide(); if(e.value=="DO") { $(e).closest(".condition").find(".value").hide(); $(e).closest(".condition").find(".compare").hide(); saveevents(e); return false; } if(e.value=="") { saveevents(e); return false; } $(e).closest(".condition").find(".compare").show(); $(e).parent().parent().find("select.compare").find(".all").show(); $(e).parent().parent().find("select.compare").find(".not-"+$(""+e.value).data("form")).hide(); if($(e).parent().parent().find("select.compare").find(":selected").css("display")=="none") { $(e).parent().parent().find("select.compare").val(""); } if($(e).closest(".condition").find(".compare").val()=="valid" || $(e).closest(".condition").find(".compare").val()=="!valid" || $(e).closest(".condition").find(".compare").val()=="null" || $(e).closest(".condition").find(".compare").val()=="!null" || $(e).closest(".condition").find(".compare").val()=="") { saveevents(e); return false; } else { $(e).closest(".condition").find(".value").show(); } $(e).parent().parent().find("select.compare").find("option.all").show(); $(e).parent().parent().find("select.compare").find("option.not-"+$(""+e.value).data("form")).hide(); if(justcompare) { saveevents(e); return false; } if(e.value=="") { $(e).parent().parent().parent().find(".action").addClass("d-none"); } else { $(e).parent().parent().parent().find(".action").removeClass("d-none"); } html=""; $(e).parent().parent().find("div.value").css("display","none"); $(e).parent().parent().find(">div.value").html(html); if(e.value=="") { saveevents(e); return false; } if($(""+e.value).data("form")=="select" ) { $(""+e.value).find("option").each(function() { ellip=""; if($(this).html().length>20) { ellip="…"; } html=html+``; }) $(e).parent().parent().find("div.value").html(html); $(e).parent().parent().find("div.value").css("display","block"); } else { if($(""+e.value).data("form")=="radio" || $(""+e.value).data("form")=="checkbox") { $(""+e.value).find(".form-check").each(function() { ellip=""; if($(this).find("label").html().length>20) { ellip="…"; } html=html+``; }) $(e).parent().parent().find("div.value").html(html); $(e).parent().parent().find("div.value").css("display","block"); } else { if($(e).parent().parent().find("select.compare").eq(0).val()=="between" || $(e).parent().parent().find("select.compare").eq(0).val()=="betweenx" || $(e).parent().parent().find("select.compare").eq(0).val()=="betweenx-i" || $(e).parent().parent().find("select.compare").eq(0).val()=="between-i") { $(e).parent().parent().find("div.value").html(`
    and
    `); $(e).parent().parent().find("div.value").css("display","block"); $("#formcontainer").find(".form-group").each(function() { $(e).parent().parent().find(".fieldlist").append(``); }); } else { //$(e).parent().parent().find("div.value").html(``); $(e).parent().parent().find("div.value").html(`
    `); $(e).parent().parent().find("div.value").css("display","block"); $("#formcontainer").find(".form-group").each(function() { $(e).parent().parent().find(".fieldlist").append(``); }); } } } if($(e).parent().parent().find(".compare").find(":selected").hasClass("d-none")) { $(e).parent().parent().find(".compare").val("="); } setTimeout(function() { toolovers();saveevents(e); },100); } function eventchangesubject(e) { $(e).parent().parent().find("select.attrlist").val(""); $(e).parent().parent().find("select.attrlist").find(".all").removeClass("d-none"); $(e).parent().parent().find("select.attrlist").find(".not-"+$(""+e.value).data("form")).addClass("d-none"); $(e).parent().parent().find("select.attrlist").trigger("change"); $(e).parent().parent().find("input.attrvalue").attr("type",$(e.value).find("input").attr("type")); saveevents(e); } function eventchangeattr(e) { $(e).parent().parent().find("input.attrvalue").attr("type",$($(e).parent().parent().find("select.subject").val()).attr("type")); $(e).parent().parent().find(".attrvalue").val(""); $(e).parent().parent().find(".attrboolean").val(""); $(e).parent().parent().find(".attrvaltype").val(""); if(e.value=="step" || e.value=="minlength" || e.value=="maxlength") { $(e).parent().parent().find(".attrvalue").prop("type","number"); } $(e).parent().parent().find(".attrvals").hide(); $(e).parent().parent().find(".attrvalue").show(); if(e.value=="disabled" || e.value=="readonly" || e.value=="required") { $(e).parent().parent().find(".attrboolean").show(); $(e).parent().parent().find(".attrvalue").hide(); } if(e.value=="min" || e.value=="max" || e.value=="value") { if($(e).parent().parent().find(".attrvaltype").val()=="value") { $(e).parent().parent().find(".attrvaltype").hide(); $(e).parent().parent().find(".attrvalue").show(); } else { $(e).parent().parent().find(".attrvaltype").show(); $(e).parent().parent().find(".attrvalue").hide(); } } saveevents(e); } function spell(e) { if (!spelled) { spelled = true; $(e).find(".hidden").show(500); setTimeout(function() { unspell(e) }, 5000) } } function unspell(e) { $(e).find(".hidden").hide(500); setTimeout(function() { spelled = false }, 2000) } function dirty() { $("#menudonatebutton").hide(); document.getElementById("dirty").value="yes"; $("#savebutton").show(); document.getElementById("savebutton").innerHTML=` Unsaved`; $("#savebutton").addClass("btn-danger"); $("#savebutton").removeClass("btn-warning btn-primary btn-success"); window.addEventListener("beforeunload", beforeUnloadHandler); } function saveform(publish) { if(typeof publish=="undefined") { publish=false; } if(document.getElementById("dirty").value=="") { return true; } $("#savebutton").show(); document.getElementById("savebutton").innerHTML=` Saving`; $("#savebutton").addClass("btn-warning"); $("#savebutton").removeClass("btn-danger btn-primary btn-success"); if($("#offcanvascontext").hasClass("show")==false) { unselect(); } localStorage.setItem("formstrap", $("#fullform").html().trim()) localStorage.setItem("formstrapjson",JSON.stringify(serialiseform())); localStorage.setItem("saved",new Date); if(localStorage.getItem("formid")!=null) { localStorage.setItem("status","unsaved"); if(publish==false) { if(document.getElementById("mainlogin")) { messagepop("Changes to the form have been saved in your browser's local storage.

    To upload changes to your formstrap account, please login to your dashboard.","computer",function() { login() ;},function() { return false; },"Log In","Not Now"); } else { messagepop("Changes to the form have been saved to your browser's local storage.

    To upload changes to your formstrap account, please view your dashboard","computer",function() { window.open("/dashboard","dashboard");},function() { return false; },"Dashboard","Not Now"); } } } $(".savenote").toggle(); propagate(true); setTimeout(function() { $("#savebutton").show(); document.getElementById("savebutton").innerHTML=` Saved`; $("#savebutton").addClass("btn-success"); $("#savebutton").removeClass("btn-danger btn-warning btn-primary"); },500); document.getElementById("dirty").value=""; $("#menudonatebutton").show(); window.removeEventListener("beforeunload", beforeUnloadHandler); } function createnewform() { $.ajax({ method: "POST", url: "/scripts/createnewform.php", }).done(function(msg) { if (msg) { designform(msg) } else { alert("There has been an error") } }) } function updatename(value) { if (document.getElementById("fieldcontextname").value == "") { document.getElementById("fieldcontextname").value = value.replace(/[^A-Z0-9]+/ig, "_"); $("#fieldcontextname").trigger("keyup") } } function propagate(sort,clone) { $("#formcontainer").find(".form-control,form-select").attr("autocomplete","off"); $("#formcontainer .formpage,#formcontainer .pagecol,#formcontainer .formrow,#formcontainer .formcol,#formcontainer .form-group").off(); $("#formcontainer .formpage,#formcontainer .pagecol,#formcontainer .formrow,#formcontainer .formcol,#formcontainer .form-group").on("contextmenu dblclick", function(e) { position=e.pageX; if(typeof position=="undefined") { position=$(this).offset().left; } if( typeof position!="undefined") { if(position<(window.innerWidth/2)) { $("#offcanvascontext").removeClass("offcanvas-start"); $("#offcanvascontext").addClass("offcanvas-end"); $("#offcanvasevents").removeClass("offcanvas-start"); $("#offcanvasevents").addClass("offcanvas-end"); } else { $("#offcanvascontext").removeClass("offcanvas-end"); $("#offcanvascontext").addClass("offcanvas-start"); $("#offcanvasevents").removeClass("offcanvas-end"); $("#offcanvasevents").addClass("offcanvas-start"); } } unselect(); e.stopPropagation(); e.preventDefault(); that=this; if($("#offcanvascontext").hasClass("show")) { getcontext(this); } else { setTimeout(function() { getcontext(that);},500); } return false }); $("#formcontainer .formpage,#formcontainer .pagecol,#formcontainer .formrow,#formcontainer .formcol,#formcontainer .form-group").on("click", function(e) { e.stopPropagation(); getcontext(this,false); }); $("#formcontainer").find(".form-group").each(function() { normalise(this); }); toolovers(); if(sort) { runsortable(); } toolovers(); if(typeof clone!="undefined") { $(clone).next().trigger("contextmenu"); } } function addpage(id) { $("#formcontainer").attr("data-sec",parseInt($("#formcontainer").attr("data-sec"))+1); if(typeof id=="undefined") { id=$("#formcontainer").attr("data-sec") } $('#formcontainer').append(`

    `); propagate(true); $("#formcontainer").find(".section").last().trigger("contextmenu"); dirty(); } function highlightdropzone(e) { if($(e.item[0]).hasClass("form-group")) { $(".fieldcontainer").css("border","2px dashed green"); $(".fieldcontainer").css("padding","5px"); } if($(e.item[0]).hasClass("pagecol")) { $(".pagecolcontainer").css("border","2px dashed green"); $(".pagecolcontainer").css("padding","5px"); } if($(e.item[0]).hasClass("formcol")) { $(".formcolcontainer").css("border","2px dashed green"); $(".formcolcontainer").css("padding","5px"); } if($(e.item[0]).hasClass("formrow")) { $(".formrowcontainer").css("border","2px dashed green"); $(".formrowcontainer").css("padding","5px"); } } function unhighlightdropzone(e) { if($(e.item[0]).hasClass("form-group")) { $(".fieldcontainer").css("border","2px dotted red"); $(".fieldcontainer").css("padding","2px"); } if($(e.item[0]).hasClass("formcol")) { $(".formcolcontainer").css("border","2px dotted red"); $(".formcolcontainer").css("padding","2px"); } if($(e.item[0]).hasClass("pagecol")) { $(".pagecolcontainer").css("border","2px dotted red"); $(".pagecolcolcontainer").css("padding","2px"); } if($(e.item[0]).hasClass("formrow")) { $(".formrowcontainer").css("border","2px dotted red"); $(".formrowcontainer").css("padding","2px"); } } function addfield(e,id) { $("#formcontainer").attr("data-field",parseInt($("#formcontainer").attr("data-field"))+1); if(typeof id=="undefined") { id=$("#formcontainer").attr("data-field") } $(e).find(".fieldcontainer").append(`
    `); propagate(true); dirty(); $(e).find(".form-group").last().trigger("contextmenu"); } ri = 0; rj = 0; function addpagecolumn(e,id) { $("#formcontainer").attr("data-pagecol",parseInt($("#formcontainer").attr("data-pagecol"))+1); if(typeof id=="undefined") { id=$("#formcontainer").attr("data-pagecol"); } $(e).find(".pagecolcontainer").append(`

    `); propagate(true); dirty(); $(e).find(".pagecol").last().trigger("contextmenu"); } var sorted = false; function runsortable() { $("#formcontainer").sortable({ items: ".formpage:visible", tolerance: "pointer", helper: "original", zIndex:10000, cursor: "move", delay:200, scroll:true, sort: function(event,ui) { checkscreen(event,ui); }, stop: function(event,ui) { propagate(false); unhighlightdropzone(ui); dirty(); }, start:function(event,ui) { highlightdropzone(ui) } }); $(".pagecolcontainer").each(function() { $(this).sortable({ items: ".pagecol", tolerance: "pointer", helper: "original", cursor: "move", connectWith: ".pagecolcontainer", delay:200, scroll:true, sort: function(event,ui) { checkscreen(event,ui); }, stop: function(event,ui) { unhighlightdropzone(ui); propagate(false); dirty(); }, start:function(event,ui) { highlightdropzone(ui) } }) }); $(".formrowcontainer").each(function() { $(this).sortable({ items: ".formrow", tolerance: "pointer", helper: "original", cursor: "move", connectWith: ".formrowcontainer", delay:200, scroll:true, sort: function(event,ui) { checkscreen(event,ui); }, stop: function(event,ui) { unhighlightdropzone(ui); propagate(false); dirty(); }, start:function(event,ui) { highlightdropzone(ui) } }) }); $(".formcolcontainer").each(function() { $(this).sortable({ items: ".formcol", connectWith: ".formcolcontainer", helper: "original", cursor: "move", tolerance: "pointer", delay:200, scroll:true, stop: function(event,ui) { unhighlightdropzone(ui); propagate(false);dirty(); }, sort: function(event,ui) { checkscreen(event,ui); }, start:function(event,ui) { highlightdropzone(ui) } }) }); $(".fieldcontainer").each(function() { $(this).sortable({ items: ".form-group", connectWith: ".fieldcontainer", helper: "original", cursor: "move", tolerance: "pointer", delay:200, scroll:true, sort: function(event,ui) { checkscreen(event,ui); }, stop: function(event,ui) { unhighlightdropzone(ui); propagate(false); if(sortablechange["parent"]!=$(ui.item[0]).parent()[0] || (sortablechange["parent"]==$(ui.item[0]).parent()[0] && sortablechange["position"]!=$(ui.item[0]).index())) { dirty(); } }, start:function(event,ui) { highlightdropzone(ui); sortablechange={"parent":$(ui.item[0]).parent()[0],"position":$(ui.item[0]).index()} } }) }) } sortablechange={}; function checkscreen(a,b) { height=document.documentElement.scrollHeight; viewport=window.innerHeight; offset=b.offset.top; scrollposition=window.scrollY; if(offset>scrollposition+viewport) { window.scroll(0,scrollposition+50); } if(offset
    `); dirty(); propagate(true); $(e).find(".formcol").last().trigger("contextmenu"); } function convert(desc) { var string=""; var html=""; $(desc).each(function() { html=$(this).html(); attrib=this.attributes; string=""; that=this; $(attrib).each(function(x,y) { attr=y.nodeName || y.name; value=$(that).attr(attr); if(attr=="class") { value=value+" mb-3"; } string=string+attr + `="` + value + `" `; }); $(this).replaceWith("
    " + html + "
    "); }); } function addrow(e,id) { $("#formcontainer").attr("data-row",parseInt($("#formcontainer").attr("data-row"))+1); if(typeof id=="undefined") { id=$("#formcontainer").attr("data-row"); } $(e).find(".formrowcontainer").append(`

    `); propagate(true); dirty(); $(e).find(".formrow").last().trigger("contextmenu"); } var that; function deletecheck(check) { $(check).parent().parent().remove(); propagate(true) } function changecss(css, container, id, value) { $("#" + id).find(container).css(css, value) } function changevalue(n, id, value) { $("#" + id).find("input").eq(n).val(value) } function changechecklabel(n, id, value) { $("#" + id).find(".checklabel").eq(n).html(value) } function getoptions(e) { $("#addoptionbuttontop").off(); $("#addoptionbuttonbottom").off(); $("#addoptionbuttontop").on("click",function() { addoption(e,"top"); }); $("#addoptionbuttonbottom").on("click",function() { addoption(e,"bottom"); }) $("#sortoptval").off(); $("#sortoptdesc").off(); $("#sortoptval").on("click",function() { SortTable($('#optionstable'),this,1,e.value) } ); $("#sortoptdesc").on("click",function() { SortTable($('#optionstable'),this,2,e.value) } ); var options=$(e).find(".form-check,option"); $("#fieldcontextoptions").html(""); unsortable("#fieldcontextoptions"); if($(options).length>0) { extra = `  ` i=0; $(options).each(function(m,n) { if($(n).find("label").length>0) { value=$(n).find("label").html(); key=$(n).find("input").val(); } else { value=$(n).html(); key=$(n).val(); } $("#fieldcontextoptions").append(`` + extra + ``); $("#fieldoptionvalue"+i).val(key); $("#fieldoptiondesc"+i).val(value); i++ }); $("#fieldcontextoptions").sortable({ "axis":"y", "stop":function() { optionsreindex(e); }, "handle":".listhandle" } ); $("#fieldcontextoptions").find("i.fa-trash-can").off(); $("#fieldcontextoptions").find("i.fa-trash-can").on("click",function() { deleteoption(this,e); }); } } function setoptions(e) { i=0; if($(e).attr("data-form")=="select") { $(e).find("select").html(""); $("#fieldcontextoptions").find("tr").each(function(n,m) { key=$(this).find("input").eq(0).val(); value=$(this).find("input").eq(1).val(); $(e).find("select").append(``); $(e).find("select").find("option").last().attr("value",key); i++; }); } else { i=0; if($(e).find(".checks").length==0) { $(e).append(`
    `); } $(e).find(".checks").html(""); $("#fieldcontextoptions").find("tr").each(function(n,m) { key=$(this).find("input").eq(0).val(); value=$(this).find("input").eq(1).val(); $(e).find(".checks").append(`
    `); i++; }); } } var toopen = ""; var getcontextfunction={}; getcontextfunction["enableonhide"]=function(a,b,c) { if(a.id=="fieldcontextenabled" && $("#fieldcontextenabled").is(":checked")) { $("#fieldcontextrequired").prop("checked",false); $(b).attr("data-required",false); } if(a.id=="fieldcontextrequired" && $("#fieldcontextrequired").is(":checked")) { $("#fieldcontextenabled").prop("checked",false); $(b).attr("data-enabled-on-hide",false); } } getcontextfunction["size"]=function(a,b,c) { $(b).removeClass("form-control-sm form-control-lg form-select-sm form-select-lg"); if($(b).attr("data-form")=="select") { if(a.value!="reg") { $(b).find("select").addClass("form-select-"+a.value); } } if($(b).attr("data-form")=="email" || $(b).attr("data-form")=="tel" || $(b).attr("data-form")=="text" || $(b).attr("data-form")=="url" || $(b).attr("data-form")=="date" || $(b).attr("data-form")=="datetime-local" || $(b).attr("data-form")=="time" || $(b).attr("data-form")=="number") { if(a.value!="reg") { $(b).find("input").addClass("form-control-"+a.value); } } } getcontextfunction["fieldnote"]=function(a,b,c) { $(b).find(".labelnote").addClass("d-none"); $(b).find(".form-text").addClass("d-none"); if($("#fieldcontextnoteshow").val()=="under") { $(b).find(".form-text").removeClass("d-none"); } if($("#fieldcontextnoteshow").val()=="tooltip") { $(b).find(".labelnote").removeClass("d-none"); } } getcontextfunction["changetype"]=function(a,b,c) { $(b).find("input.form-control,select,textarea").attr("autocomplete","off"); if(a.value!="textarea" && a.value!="radio" && a.value!="select" && a.value!="checkbox" && $(b).attr("data-original")!="textarea" && $(b).attr("data-original")!="checkbox" && $(b).attr("data-original")!="radio" && $(b).attr("data-original")!="select") { $(b).find("input").val(""); if(a.value=="password") { $(b).find("input"). attr("autocomplete","new-password"); } } } getcontextfunction["newlines"]=function(a,b,c) { if($(a).val()=="yes") { $(b).find("#"+c +"description").css("white-space","pre-wrap"); $(b).find("."+c +"-description").css("white-space","pre-wrap"); } else { $(b).find("#"+c +"description").css("white-space",""); $(b).find("."+c +"-description").css("white-space",""); } } getcontextfunction["width"]=function(a,b,c) { component=JSON.parse($(a).attr("data-component").replaceAll("'",'"')); breakpoints=[]; breakpoints[0]="-xs"; breakpoints[1]="-sm"; breakpoints[2]="-md"; breakpoints[3]="-lg"; breakpoints[4]="-xl"; breakpoints[5]="-xxl"; $(component).each(function(j,k) { if(k=="this") { ob=$(b); } else { ob=$(b).find(k); } $(breakpoints).each(function(x,y) { r=y; if(y=="-xs") { r=""; $(ob).removeClass("col"); } $(ob).removeClass("col"+r+"-1 col"+r+"-2 col"+r+"-3 col"+r+"-4 col"+r+"-5 col"+r+"-6 col"+r+"-7 col"+r+"-8 col"+r+"-9 col"+r+"-10 col"+r+"-11 col"+r+"-12"); if($(ob).attr("data-width"+y)) { $(ob).addClass($(ob).attr("data-width"+y)); } }); if(k=="#formlogocontainer" && $("#formcontextlogo").val()=="") { $(ob).addClass("d-none"); } }); } getcontextfunction["alignment"]=function(a,b,c) { component=JSON.parse($(a).attr("data-component").replaceAll("'",'"')); breakpoints=[]; breakpoints[0]=""; breakpoints[1]="-sm"; breakpoints[2]="-md"; breakpoints[3]="-lg"; breakpoints[4]="-xl"; breakpoints[5]="-xxl"; $(component).each(function(j,k) { $(breakpoints).each(function(x,y) { $(b).find(k).removeClass("text"+y+"-start text"+y+"-end text"+y+"-center"); if($(k).attr("data-align"+y)) { $(b).find(k).addClass($(k).attr("data-align"+y)); } }); }); } getcontextfunction["changepage"]=function(a,b,c) { if($("[data-page]").length>1) { $("#sectioncontextpage").parent().parent().show(); } else { $("#sectioncontextpage").parent().parent().hide(); } } getcontextfunction["taheight"]=function(a,b,c) { if(document.getElementById("fieldcontextautoheight").checked) { if(parseInt(document.getElementById("fieldcontexttextareaheight").value)>0) { $(b).find("textarea").css("min-height",parseInt(document.getElementById("fieldcontexttextareaheight").value)+"px"); $(b).find("textarea").css("height",""); } else { $(b).find("textarea").css("min-height",""); } } else { if(parseInt(document.getElementById("fieldcontexttextareaheight").value)>0) { $(b).find("textarea").css("height",parseInt(document.getElementById("fieldcontexttextareaheight").value)+"px"); } else { $(b).find("textarea").css("height",""); } } $(b).attr("data-rendered-height",$(b).find("textarea").css("height")); $(b).find("textarea").off(); $(b).find("textarea").on("mouseup",function() { if(parseInt($(b).find("textarea").css("height"))!=parseInt(document.getElementById("fieldcontexttextareaheight").value)) { document.getElementById("fieldcontexttextareaheight").value=parseInt($(b).find("textarea").css("height")); $("#fieldcontexttextareaheight").trigger("blur"); } }); } getcontextfunction["colours"]=function(a,b,c) { if(a.id=="formcontextpagecolour") { $("body").css("background-color",a.value); } if(a.id=="formcontexttextcolour") { $("#fullformcontainer").css("color",a.value); } } getcontextfunction["replicable"]=function(a,b,c) { if(c=="sectioncolumn") { $("#sectioncolumncontextreplicable").parent().parent().show(); if($(b).find(".formrow[data-replicable=yes]").length>0 || $(b).find("[data-form=checkbox]").length>0) { $("#sectioncolumncontextreplicable").val("no"); $("#sectioncolumncontextreplicable").parent().parent().hide(); $(b).attr("data-replicable","no"); } } if(c=="row") { $("#rowcontextreplicable").parent().parent().show(); if($(b).closest(".pagecol[data-replicable=yes]").length>0 || $(b).find("[data-form=checkbox]").length>0) { $("#rowcontextreplicable").val("no"); $("#rowcontextreplicable").parent().parent().hide(); $(b).attr("data-replicable","no"); } } if($(b).attr("data-replicable")=="yes") { $("#"+c+"context").find(".replbutts").closest(".row").show(); } else { $("#"+c+"context").find(".replbutts").closest(".row").hide(); $(b).removeAttr("data-replicabledelete"); $(b).removeAttr("data-replicableadd"); } } getcontextfunction["twocolumns"]=function(a,b,c) { if(a.checked) { $(b).find(".checks").addClass("twocols"); } else { $(b).find(".checks").removeClass("twocols"); } } getcontextfunction["pagination"]=function(a,b,c) { $("#formcontextpagination").find("a,button").attr("disabled",true); if($(a).attr("id")=="formcontextpagination") { if($("[data-page]").length>1) { $(".formcontextpaginationitems").show(); countpages(); } else { $(".formcontextpaginationitems").hide(); } $("#formcontextpaginationcontainer").find("nav").hide(); if(a.value) { $("#formcontextpaginationcontainer").find("nav#"+a.value).show(); } } } getcontextfunction["logo"]=function(a,b,c) { if(a.value=="") { $("#formlogocontainer").addClass("d-none"); $("#uplogobutton").css("display","inline"); return false; } else { $("#formlogo").css("aspect-ratio",""); $("#formlogocontainer").removeClass("d-none"); $("#uplogobutton").css("display","none"); $("#formlogo").attr("data-aspectratio",$("#formlogo").width()/$("#formlogo").height()); $("#formlogo").css("aspect-ratio",parseFloat($("#formlogo").width())/parseFloat($("#formlogo").height())); } } getcontextfunction["cardify"]=function(a,b,c) { if($("#"+c+"contextcard").val()=="Yes") { $("."+c+"contextcardoptions").show(); } else { $("."+c+"contextcardoptions").hide(); } if($(b).find("."+c+"-header").html()=="") { if($(b).find("."+c+"-header").addClass("d-none")); } else { if($(b).find("."+c+"-header").addClass("d-block")); } if($(b).find("."+c+"-description").html()=="") { if($(b).find("."+c+"-description").addClass("d-none")); } else { if($(b).find("."+c+"-description").addClass("d-block")); } }; var setcontextfunction={}; setcontextfunction["inputgroup"]=function(a,b,c) { var t,s; if($(b).find(".input-group").length>0) { $(b).find(".input-group").removeClass("input-group-sm input-group-lg") s=$(b).attr("data-input-size"); if(s!="reg" && s!="" && typeof s!="undefined") { s="input-group-"+s; $(b).find(".input-group").addClass(s); } if(a.id=="fieldcontextprepend") { $(b).find(".group-prepend").remove(); if(a.value) { $(b).find(".input-group").prepend(`
    ` + a.value + `
    `); } } else { $(b).find(".group-append").remove(); if(a.value) { $(b).find(".input-group").append(`
    ` + a.value + `
    `); } } } else { t=$(b).find("select,input,textarea").eq(0).prop("outerHTML"); s=$(b).attr("data-input-size"); if(s!="reg" && s!="" && typeof s!="undefined") { s="input-group-"+s; } else { s=""; } $(b).find("select,input,textarea").eq(0).replaceWith(`
    ` + t + `
    `); setcontextfunction["inputgroup"](a,b,c); } } setcontextfunction["enableonhide"]=function(a,b,c) { if(a.id=="fieldcontextenabled" && $("#fieldcontextenabled").is(":checked")) { $("#fieldcontextrequired").prop("checked",false); $(b).attr("data-required",false); } if(a.id=="fieldcontextrequired" && $("#fieldcontextrequired").is(":checked")) { $("#fieldcontextenabled").prop("checked",false); $(b).attr("data-enabled-on-hide",false); } } setcontextfunction["classcheck"]=function (a,b,c) { $.ajax({ method:"POST", url:"/scripts/checkbsclass.php", dataType:"json", data:{group:a.value} } ).done(function(msg) { if(msg.response!="OK") { messagepop("The group you have specified is a reserved value and has been removed.

    Please choose another name for the group

    Why?
    formstrap groups are stored in HTML class attributes so cannot clash with class names used by loaded libraries (e.g. Bootstrap).
    ","exclamation-circle"); a.value=""; } }); } setcontextfunction["size"]=function(a,b,c) { $(b).find("input,select").removeClass("form-control-sm form-control-lg form-select-sm form-select-lg"); if($(b).find(".input-group").length>0) { $(b).find(".input-group").removeClass("input-group-sm input-group-lg"); if(a.value!="reg") { $(b).find(".input-group").addClass("input-group-"+a.value); } } else { if($(b).attr("data-form")=="select") { if(a.value!="reg") { $(b).find("select").addClass("form-select-"+a.value); } } if($(b).attr("data-form")=="email" || $(b).attr("data-form")=="tel" || $(b).attr("data-form")=="text" || $(b).attr("data-form")=="url" || $(b).attr("data-form")=="date" || $(b).attr("data-form")=="datetime-local" || $(b).attr("data-form")=="time" || $(b).attr("data-form")=="number") { if(a.value!="reg") { $(b).find("input").addClass("form-control-"+a.value); } } } } setcontextfunction["fieldnote"]=function(a,b,c) { $(b).find(".labelnote").addClass("d-none"); $(b).find(".form-text").addClass("d-none"); if($("#fieldcontextnoteshow").val()=="under") { $(b).find(".form-text").removeClass("d-none"); } if($("#fieldcontextnoteshow").val()=="tooltip") { $(b).find(".labelnote").removeClass("d-none"); } } setcontextfunction["newlines"]=function(a,b,c) { if($(a).val()=="yes") { $(b).find("#"+c +"description").css("white-space","pre-wrap"); $(b).find("."+c +"-description").css("white-space","pre-wrap"); } else { $(b).find("#"+c +"description").css("white-space",""); $(b).find("."+c +"-description").css("white-space",""); } } setcontextfunction["width"]=function(a,b,c) { component=JSON.parse($(a).attr("data-component").replaceAll("'",'"')); breakpoints=[]; breakpoints[0]="-xs"; breakpoints[1]="-sm"; breakpoints[2]="-md"; breakpoints[3]="-lg"; breakpoints[4]="-xl"; breakpoints[5]="-xxl"; $(component).each(function(j,k) { if(k=="this") { ob=$(b); } else { ob=$(b).find(k); } $(breakpoints).each(function(x,y) { r=y; if(y=="-xs") { r=""; ob.removeClass("col"); } ob.removeClass("col"+r+"-1 col"+r+"-2 col"+r+"-3 col"+r+"-4 col"+r+"-5 col"+r+"-6 col"+r+"-7 col"+r+"-8 col"+r+"-9 col"+r+"-10 col"+r+"-11 col"+r+"-12"); if(ob.attr("data-width"+y)) { ob.addClass(ob.attr("data-width"+y)); } }); if(k=="#formlogocontainer" && $("#formcontextlogo").val()=="") { ob.addClass("d-none"); } }); } setcontextfunction["alignment"]=function(a,b,c) { component=JSON.parse($(a).attr("data-component").replaceAll("'",'"')); breakpoints=[]; breakpoints[0]=""; breakpoints[1]="-sm"; breakpoints[2]="-md"; breakpoints[3]="-lg"; breakpoints[4]="-xl"; breakpoints[5]="-xxl"; $(component).each(function(j,k) { $(breakpoints).each(function(x,y) { $(b).find(k).removeClass("text"+y+"-start text"+y+"-end text"+y+"-center"); if($(k).attr("data-align"+y)) { $(b).find(k).addClass($(k).attr("data-align"+y)); } }); }); } setcontextfunction["taheight"]=function(a,b,c) { if(document.getElementById("fieldcontextautoheight").checked) { if(parseInt(document.getElementById("fieldcontexttextareaheight").value)>0) { $(b).find("textarea").css("min-height",parseInt(document.getElementById("fieldcontexttextareaheight").value)+"px"); $(b).find("textarea").css("height",""); } else { $(b).find("textarea").css("min-height",""); } } else { if(parseInt(document.getElementById("fieldcontexttextareaheight").value)>0) { $(b).find("textarea").css("height",parseInt(document.getElementById("fieldcontexttextareaheight").value)+"px"); } else { $(b).find("textarea").css("height",""); } } } setcontextfunction["replicable"]=function(a,b,c) { if(c=="sectioncolumn") { $("#sectioncolumncontextreplicable").parent().parent().show(); if($(b).find(".formrow[data-replicable=yes]").length>0 || $(b).find("[data-form=checkbox]").length>0) { $("#sectioncolumncontextreplicable").val("no"); $("#sectioncolumncontextreplicable").parent().parent().hide(); $(b).attr("data-replicable","no"); } } if(c=="row") { $("#rowcontextreplicable").parent().parent().show(); if($(b).closest(".pagecol[data-replicable=yes]").length>0 || $(b).find("[data-form=checkbox]").length>0) { $("#rowcontextreplicable").val("no"); $("#rowcontextreplicable").parent().parent().hide(); $(b).attr("data-replicable","no"); } } if($(b).attr("data-replicable")=="yes") { $("#"+c+"context").find(".replbutts").closest(".row").show(); } else { $("#"+c+"context").find(".replbutts").closest(".row").hide(); $(b).removeAttr("data-replicabledelete"); $(b).removeAttr("data-replicableadd"); } dirty(); } setcontextfunction["twocolumns"]=function(a,b,c) { if(a.checked) { $(b).find(".checks").addClass("twocols"); } else { $(b).find(".checks").removeClass("twocols"); } dirty(); checkfield(b); } setcontextfunction["changetype"]=function(a,b,c) { if(typeof $(b).find("input,textarea").attr("placeholder")!="undefined") { placeholder=`placeholder="`+$(b).find("input,textarea").attr("placeholder") + `" `; } else { placeholder=``; } if($(b).attr("data-floatinglabel")=="true" && placeholder=="") { placeholder=$(b).find(".label-text").text(); } // if the original type and the new type are INPUT elements of any type - just change the type if(a.value!="textarea" && a.value!="radio" && a.value!="select" && a.value!="checkbox" && $(b).attr("data-original")!="textarea" && $(b).attr("data-original")!="checkbox" && $(b).attr("data-original")!="radio" && $(b).attr("data-original")!="select") { if(a.value=="range") { $(b).find("input").eq(0).removeClass("form-control form-control-lg form-control-sm"); $(b).find("input").eq(0).addClass("form-range"); $(b).removeAttr("data-size"); } if($(b).attr("data-original")=="range") { $(b).find("input").eq(0).removeClass("form-range"); $(b).find("input").eq(0).addClass("form-control"); $(b).attr("data-size","reg"); } if(a.value=="password") { $(b).find("input"). attr("autocomplete","new-password"); } else { $(b).find("input").attr("autocomplete","off"); } $(b).find("input").eq(0).attr("type",a.value); } else { if(typeof $(b).attr("data-name")!="undefined") { name=`name="`+$(b).attr("data-name") + `" `; } else { name=""; } if($(b).attr("data-floatinglabel")=="true" && placeholder=="") { placeholder=$(b).find(".label-text").text(); } if(typeof $(b).attr("data-input-size")!="undefined") { size=$(b).attr("data-input-size"); } else { size=""; } if(a.value=="textarea") { // if the new type is a text area and the original is INPUT (not check/radio) or SELECT if($(b).attr("data-original")=="checkbox" || $(b).attr("data-original")=="radio") { $(b).removeAttr("data-twocols"); label=$(b).find("legend").html() $(b).find("fieldset").replaceWith(``); } else { $(b).find("input.form-control,select.form-select").eq(0).replaceWith(``); } } if(a.value=="select") { // if the new type is a SELECT if(size=="reg") { size="" } else { if(size!="") { size="form-select-"+size; } else { size=""; } } if($(b).attr("data-original")=="radio" || $(b).attr("data-original")=="checkbox") { // and the old type is radio or check $(b).removeAttr("data-twocols"); label=$(b).find("legend").html() $(b).find("fieldset").replaceWith(``); setoptions(b); } else { // and the old type is INPUT (not radio/check) , TEXTAREA $(b).find("input.form-control,textarea.form-control").eq(0).replaceWith(``); } } // if the new type is check or radio if(a.value=="checkbox" || a.value=="radio") { var t; t=$(b).find(".input-group").find("input,select,textarea").eq(0).prop("outerHTML"); if(t) { $(b).removeAttr("data-prepend"); $(b).removeAttr("data-append"); $("#fieldcontextprepend").val(""); $("#fieldcontextappend").val(""); $(b).find(".input-group").replaceWith(t); } if($(b).attr("data-original")=="checkbox" || $(b).attr("data-original")=="radio") { // and old type is check or radio - just redraw the options setoptions(b); } else { // and the old type is SOMETHING else create the fieldset and legend and check container and then redraw the options. legend=$(b).find("label").html(); note=$(b).find(".form-text").prop("outerHTML"); $(b).find(".form-control,.form-select").parent().html(""); $(b).append(`
    `+legend+`
    `+note); setoptions(b); } } if(a.value=="email" || a.value=="tel" || a.value=="text" || a.value=="url" || a.value=="range" || a.value=="password" || a.value=="date" || a.value=="datetime-local" || a.value=="time" || a.value=="number" ) { newclass="form-control "; if(size=="reg" ) { size="" } else { if(size!="") { size="form-control-"+size; } else { size=""; } } if(a.value=="range") { newclass="form-range "; size=""; } if($(b).attr("data-original")=="checkbox" || $(b).attr("data-original")=="radio") { $(b).removeAttr("data-twocols"); label=$(b).find("legend").html() $(b).find("fieldset").replaceWith(``); } else { $(b).find("select.form-select,textarea.form-control").eq(0).replaceWith(``); } } } if($(b).attr("data-form")=="number" || $(b).attr("data-form")=="date" || $(b).attr("data-form")=="datetime-local" || $(b).attr("data-form")=="time" || $(b).attr("data-form")=="range" || $(b).attr("data-form")=="checkbox" || $(b).attr("data-form")=="radio" || $(b).attr("data-form")=="select") { $(b).find("input").removeAttr("minlength maxlength data-tooshort data-toolong "); } if($(b).attr("data-form")=="text" || $(b).attr("data-form")=="url" || $(b).attr("data-form")=="email" || $(b).attr("data-form")=="select" || $(b).attr("data-form")=="checkbox" || $(b).attr("data-form")=="radio" || $(b).attr("data-form")=="textarea" || $(b).attr("data-form")=="tel" || $(b).attr("data-form")=="password") { $(b).find("input,select,textarea").eq(0).removeAttr("min max step data-rangeover data-rangeunder data-stepmismatch"); } $(b).attr("data-original",$(b).attr("data-form")); $(b).data("form",$(b).attr("data-form")); getcontext(b); dirty(); } setcontextfunction["pagination"]=function(a,b,c) { $("#formcontextpagination").find("a,button").attr("disabled",true); countpages(); dirty(); getcontext(b); } setcontextfunction["changepage"]=function(a,b,c) { z=a.value; $("#formcontainer").find(".formpage").sort(sort_sections) .appendTo("#formcontainer"); setTimeout(function() { countpages(z); } ,250); dirty(); } setcontextfunction["favicon"]=function(a,b,c) { if(a.value=="") { a.value="https://formstrap.com/favicon.png"; $("#favicon").attr("href",a.value); dirty(); return false; } $.ajax({ method:"GET", url:a.value}).done(function(c,d,e) { if(e.getResponseHeader("content-type")!="image/png" && e.getResponseHeader("content-type")!="image/vnd.microsoft.icon" && e.getResponseHeader("content-type")!="image/x-icon") { messagepop("The URL provided is not a valid image file type for the icon

    Valid file types: PNG and ICO","exclamation-circle"); $(a).val(""); return false; } $("#favicon").attr("href",a.value); }).fail(function(e) { messagepop("The URL provided for the Icon

    " + a.value + "

    has returned an error code : " + e.status,"exclamation-circle"); $(a).val(""); }) dirty(); } setcontextfunction["logo"]=function(a,b,c) { if(a.value=="") { $("#formlogocontainer").addClass("d-none"); $("#uplogobutton").css("display","inline"); dirty(); return false; } $.ajax({ method:"GET", type:"HEAD", url:a.value}).done(function(c,d,e) { if(e.getResponseHeader("content-type")!="image/png" && e.getResponseHeader("content-type")!="image/jpeg" && e.getResponseHeader("content-type")!="image/webp" && e.getResponseHeader("content-type")!="image/gif" ) { messagepop("The URL provided is not a valid image file type.

    Valid file types: PNG, JPEG, WEBP, and GIF","exclamation-circle"); $(a).val(""); return false; } $("#formlogo").css("aspect-ratio",""); $("#formlogo").attr("src",a.value); $("#formlogocontainer").removeClass("d-none"); $("#uplogobutton").css("display","none"); $("#formlogo").on("load",function() { $("#formlogo").attr("data-aspectratio",$("#formlogo").width()/$("#formlogo").height()); $("#formlogo").css("aspect-ratio",$("#formlogo").width()/$("#formlogo").height()); } ); }).fail(function(e) { if(e.status>0) { messagepop("The URL provided for the Logo

    " + a.value.replaceAll("/","​/") + "

    has returned an error code : " + e.status,"exclamation-circle"); } else { messagepop("The URL provided for the Logo

    " + a.value.replaceAll("/","​/") + "

    has returned an undefined error. Please inspect the browser's console.","exclamation-circle"); } $(a).val(""); $("#uplogobutton").css("display","inline"); $("#formlogocontainer").addClass("d-none"); }); dirty(); } setcontextfunction["colours"]=function(a,b,c) { if(a.id=="formcontextpagecolour") { $("body").css("background-color",a.value); } if(a.id=="formcontexttextcolour") { $("#fullformcontainer").css("color",a.value+"!important"); } dirty(); } setcontextfunction["floatinglabel"]=function(a,b,c) { $(b).removeClass("form-floating"); if($(a).is(":checked")) { $(b).addClass("form-floating"); label=$(b).find("label"); note=$(b).find("div.form-text"); input=$(b).find("input,select,textarea").not("[type=checkbox]").not("[type=radio]").eq(0); if($(input).attr("placeholder")=="" || typeof $(input).attr("placeholder")=="undefined") { $(input).attr("placeholder",$(label).text().trim()); } $(b).html(""); $(b).append($(input).prop("outerHTML")); $(b).append($(label).prop("outerHTML")); $(b).append($(note).prop("outerHTML")); } else { label=$(b).find("label"); input=$(b).find("input,select,textarea").not("[type=checkbox]").not("[type=radio]").eq(0); note=$(b).find("div.form-text"); $(b).html(""); $(b).append($(label).prop("outerHTML")); $(b).append($(input).prop("outerHTML")); $(b).append($(note).prop("outerHTML")); } dirty(); checkfield(b); } setcontextfunction["margin"]=function(a,b,c) { $(b).removeClass (function (index, className) { return (className.match (/(^|\s)m(b|e|s|t)-\S+/g) || []).join(' '); }); if($("#"+c+"contextmargintop").val()) { $(b).addClass($("#"+c+"contextmargintop").val()); } if($("#"+c+"contextmarginstart").val()) { $(b).addClass($("#"+c+"contextmarginstart").val()); } if($("#"+c+"contextmarginbottom").val()) { $(b).addClass($("#"+c+"contextmarginbottom").val()); } if($("#"+c+"contextmarginend").val()) { $(b).addClass($("#"+c+"contextmarginend").val()); } dirty(); } setcontextfunction["padding"]=function(a,b,c) { return false; $(b).removeClass (function (index, className) { return (className.match (/(^|\s)p(b|e|s|t)-\S+/g) || []).join(' '); }); if($("#"+c+"contextpaddingtop").val()) { $(b).addClass($("#"+c+"contextpaddingtop").val()); } if($("#"+c+"contextpaddingstart").val()) { $(b).addClass($("#"+c+"contextpaddingstart").val()); } if($("#"+c+"contextpaddingbottom").val()) { $(b).addClass($("#"+c+"contextpaddingbottom").val()); } if($("#"+c+"contextpaddingend").val()) { $(b).addClass($("#"+c+"contextpaddingend").val()); } dirty(); } setcontextfunction["initiallyvisible"]=function(a,b,c) { $(b).removeClass("visibleyes visibleno"); if(($(a).get(0).tagName=="SELECT" && $(a).val()=="yes") || ( $(a).get(0).tagName=="INPUT" && $(a).is(":checked")) ) { $(b).addClass("visibleyes"); } else { $(b).addClass("visibleno"); } dirty(); } setcontextfunction["inputclass"]=function(a,b,c) { if($(b).data("form")!="checkbox" && $(b).data("form")!="radio" && $(b).data("form")!="textarea") { $(b).find("input,textarea,select").removeClass("form-control-sm form-control-lg form-select-sm form-select-lg"); if($(a).val()!="reg") { $(b).find("input,textarea").addClass("form-control-"+$(a).val()); $(b).find("select").addClass("form-select-"+$(a).val()); } } dirty(); if(c=="field") { checkfield(b); } }; setcontextfunction["cardify"]=function(a,b,c) { if($("#"+c+"contextcard").val()=="Yes") { $("."+c+"contextcardoptions").show(); if($(b).attr("data-card")=="yes") { titleobject=$(b).find("."+c+"-header").eq(0); descobject=$(b).find("."+c+"-description").eq(0); $(titleobject).addClass("card-header"); if($(titleobject).html()!="") { $(titleobject).removeClass("d-none"); } else { $(titleobject).addClass("d-none"); } if($(descobject).html()!="") { $(descobject).removeClass("d-none"); } else { $(descobject).addClass("d-none"); } return false; } else { titleobject=$(b).find("."+c+"-header").eq(0); descobject=$(b).find("."+c+"-description").eq(0); $(titleobject).addClass("card-header"); if($(titleobject).html()!="") { $(titleobject).removeClass("d-none"); } else { $(titleobject).addClass("d-none"); } if($(descobject).html()!="") { $(descobject).removeClass("d-none"); } else { $(descobject).addClass("d-none"); } title=$(titleobject).prop("outerHTML"); description=$(descobject).prop("outerHTML"); container=$(b).find(".subcontainer").eq(0).prop("outerHTML"); $(b).find("."+c+"-description").eq(0).remove(); $(b).find("."+c+"-header").eq(0).remove(); cardcolour=""; if(typeof $(b).data("cardcolour")!="undefined") { cardcolour=$(b).data("cardcolour") } html=`
    `+title+`
    `+description+container+`
    `; $(b).html(html); $(b).attr("data-card","Yes"); } } else { $("."+context+"contextcardoptions").hide(); titleobject=$(b).find("."+c+"-header"); descobject=$(b).find("."+c+"-description").eq(0); $(titleobject).removeClass("card-header").eq(0); if($(titleobject).html()) { $(titleobject).removeClass("d-none"); } if($(descobject).html()) { $(descobject).removeClass("d-none"); } title=$(titleobject).prop("outerHTML"); description=$(b).find("."+c+"-description").prop("outerHTML"); container=$(b).find(".subcontainer").eq(0).prop("outerHTML"); $(b).find("."+c+"-description").eq(0).remove(); $(b).find("."+c+"-header").eq(0).remove(); html=title+description+container; $(b).html(html); } propagate(true); dirty(); }; function getcontext(e,cshow) { unselect(); $(e).css("border-color", "red"); document.getElementById("selectedcomponent").value=e.id; if(typeof cshow=="undefined") { cshow=true; } var subcomponent; $("#contextsubbuttons").show(); $("#fieldeventbutton").parent().hide(); $("#addsiblingbutton").parent().show(); $("#fieldeventbutton").off(); $("#addsiblingbutton").off(); $("#saveastemplate").off(); $("#addsomethingbutton").off(); $("#deletebutton").off(); if(typeof $(e).attr("data-customid")!="undefined" && $(e).attr("data-customid")!="" ) { $(".contextid").html(""+$(e).attr("data-customid")); $(".contextsystemid").html("#"+e.id); } else { $(".contextsystemid").html("#"+e.id); $(".contextid").html("#"+e.id); } if(typeof cshow=="undefined") { cshow=true; } $("#offcanvascontext").find("input,select,textarea").off(); $("#context").find(".card").hide(); if($(e).hasClass("form-group")) { $("#eventtrigger").html(``); context="field"; desc="Field"; $("#fieldcontextbody").find(".row").hide(); $("#fieldcontextbody").find(".all").show(); $("#fieldcontextbody").find("."+$(e).data("form")).show(); $("#fieldeventbutton").parent().show(); $("#addsomethingbutton").parent().hide(); $("#addsiblingbutton").parent().show(); subcomponent=""; if($(e).closest("[data-replicable=yes]").length>0) { $("#fieldeventbutton").parent().hide(); } else { $("#fieldeventbutton").parent().show(); $("#fieldeventbutton").on("click",function() { eventmeta(e); }); } $("#addsiblingbutton").parent().show(); $("#saveastemplate").parent().show(); $("#addfromtemplatebutton").parent().hide(); } if($(e).hasClass("formpage")) { context="section"; desc="Section"; subcomponent="Section Column"; subcomponentfn=function() { addpagecolumn(e); } subcomponenttemplatefn=function() { viewtemplates(e,"sectioncolumn"); } $("#addsiblingbutton").parent().show(); $("#saveastemplate").parent().show(); $("#addfromtemplatebutton").parent().show(); } if($(e).hasClass("pagecol")) { context="sectioncolumn"; desc="Section Column"; subcomponent="Row"; subcomponentfn=function() { addrow(e); } subcomponenttemplatefn=function() { viewtemplates(e,"row"); } $("#addsiblingbutton").parent().show(); $("#saveastemplate").parent().show(); $("#addfromtemplatebutton").parent().show(); } if($(e).hasClass("formrow")) { context="row"; desc="Row"; subcomponent="Column"; subcomponentfn=function() { addcolumn(e); } subcomponenttemplatefn=function() { viewtemplates(e,"column"); } $("#addsiblingbutton").parent().show(); $("#saveastemplate").parent().show(); $("#addfromtemplatebutton").parent().show(); } if($(e).hasClass("formcol")) { context="column"; desc="Column"; subcomponent="Field"; subcomponentfn=function() { addfield(e); } subcomponenttemplatefn=function() { viewtemplates(e,"field"); } $("#addsiblingbutton").parent().show(); $("#saveastemplate").parent().show(); $("#addfromtemplatebutton").parent().show(); } if($(e).attr("id")=="fullform") { context="form"; desc="Form"; subcomponent="Section"; subcomponentfn=function() { addpage(); } $(".contextsystemid").html("#"+$(e).find("#formcontainer").attr("data-id")); subcomponenttemplatefn=function() { viewtemplates(e,"section"); } if($(e).find("#formcontainer").attr("data-name")) { $(".contextid").html(""+$(e).find("#formcontainer").attr("data-name")); } else { $(".contextid").html("#"+$(e).find("#formcontainer").attr("data-id")); } $("#contextsubbuttons").show(); $("#addsiblingbutton").parent().hide(); $("#saveastemplate").parent().hide(); $("#addfromtemplatebutton").parent().show(); } if(context) { setTimeout(function() { e.scrollIntoView(true); },1000); $("#addsiblingbutton").on("click",function() { clone(e); }); $("#saveastemplate").on("click",function() { savetemplate(e,context); }); $("#deletebutton").on("click",function() { deletecomponent(e,context,desc); }); if(subcomponent) { $(".subcomponent").html(subcomponent); $("#addsomethingbutton").parent().show(); $("#addsomethingbutton").on("click",subcomponentfn); } if(typeof subcomponenttemplatefn=="function") { $("#addfromtemplatebutton").off(); $("#addfromtemplatebutton").on("click",subcomponenttemplatefn); } else { $("#addfromtemplatebutton").parent().hide(); } $(".contexttype").html(desc); $("#"+context+"context").show(); $("#"+context+"context").find("input:checkbox").on("change",function(event) { docontext(context,this,e); }); $("#"+context+"context").find("textarea,input:not(:checkbox)").on("change",function(event) { docontext(context,this,e); }); $("#"+context+"context").find("select").on("change",function(event) { docontext(context,this,e); }); $("#"+context+"context").find("textarea,select,input:not(:checkbox)").on("focus",function(event) { $(this).css("background-color","lightGreen");}); $("#"+context+"context").find("textarea,select,input:not(:checkbox)").on("blur",function(event) { $(this).css("background-color","");}); retrievecontext(e,context,cshow); } else { offcanvasList[0].hide(); } } function deletecomponent(e,context,type) { var temp=e; if(type=="Form") { m="the Form? All form data will be deleted."; n="the Form"; } else { m="the highlighted "+ type +" component?"; n="it"; } messagepop("Are you sure that you want to delete "+m+"

    It will NOT be possible to recover it.","trash",function() { dodelete(e,context,type); },function() { $("#messagebod").html("");return false ; },"Delete","Cancel",null,"modal-sm",null,null,null,null,null,null); } function dodelete(e,context,type) { unselect(); id=$(e).attr("id"); $(e).fadeOut(500,function() { $(e).remove(); dirty(); propagate(true); if(type=="Form") { localStorage.removeItem('formstrap'); localStorage.removeItem('formstrapjson'); localStorage.removeItem("storagewarned"); localStorage.removeItem("formid"); localStorage.removeItem("saved"); localStorage.removeItem("events"); localStorage.removeItem("name"); localStorage.removeItem("status"); localStorage.removeItem('saveto'); window.removeEventListener("beforeunload", beforeUnloadHandler); location.reload(); } if(type=="Field") { events=JSON.parse(localStorage.getItem("events")); if(typeof events["#"+id]!=undefined) { delete events["#"+id]; } localStorage.setItem("events",JSON.stringify(events)); } if(type=="Section") { if($(".section[data-page="+document.getElementById("selectedpage").value+"]").length==0) { countpages($(".section").data("page")); } } }); } function retrievecontext(e,context,cshow) { $("#offcanvascontext").find("form").trigger("reset"); var booleanlookup={}; booleanlookup["disabled"]=true; booleanlookup["readonly"]=true; booleanlookup["true"]=true; booleanlookup["false"]=false; $("#"+context+"context").find("input,select,textarea").each(function() { if(typeof $(this).data("component")!="undefined") { components=JSON.parse($(this).data("component").replaceAll("'",'"')); if(typeof $(this).data("attr")!="undefined") { attributes=JSON.parse($(this).data("attr").replaceAll("'",'"')); if(components[0]=="this") { z=$(e); } else { z=$(e).find(components[0]); } if(attributes[0]=="html") { if(typeof $(z).html()!="undefined") { if($(this).get(0).tagName=="TEXTAREA") { $(this).html($(z).html()); } else { $(this).val($(z).html()); } $(z).removeClass("d-none"); } else { $(this).val(""); $(z).addClass("d-none"); } } else { if(typeof $(z).attr(attributes[0])!="undefined") { if($(this).attr("type")=="checkbox") { $(this).prop("checked",booleanlookup[$(z).attr(attributes[0])]); } else { $(this).val($(z).attr(attributes[0]).replaceAll("[]","")); } } } } } if($(this).data("fn")) { if(typeof getcontextfunction[$(this).data("fn")]=="function") { getcontextfunction[$(this).data("fn")](this,e,context); } } }); if(cshow) { offcanvasList[0].show(); } //location.href="#metadata"; if(context=="field" ) { $(e).attr("data-original",$(e).attr("data-form")); checkfield(e); getoptions(e); } } function checkfield(e) { // show fields known to be initially releveant for the field type of the component e $("#fieldcontext").find(".fieldcon").hide(); $("#fieldcontext").find(".all").show(); $("#fieldcontext").find("."+$(e).attr("data-form")).show(); $("#fieldcontext").find(".fa-function,.formulabutton").off(); $(".fa-calendar-days").off(); $(".fa-calendar-days").hide(); $(".fa-function").hide(); $(".formulabutton").hide(); $("#fieldcontextmin").show(); $("#fieldcontextmax").show(); $("#fieldcontextdefault").show(); if($(e).attr("data-floatinglabel")=="true" && ($(e).find("input,textarea").attr("placeholder")=="" || typeof $(e).find("Input,textarea").attr("placeholder")=="undefined")) { $(e).find("input,textarea").attr("placeholder",$(e).find(".label-text").text()); } if($(e).attr("data-input-size")=="reg") { $("#fieldcontextfloatinglabel").closest("."+$(e).attr("data-form")).show(); } else { $("#fieldcontextfloatinglabel").closest("."+$(e).attr("data-form")).hide(); } if($(e).find("label").find(".labeltext").html()=="") { $(e).find("label").hide(); } else { $(e).find("label").show(); } if($(e).attr("data-floatinglabel")=="true" && $("#fieldcontextfloatinglabel").is(":visible")) { $("#fieldcontexttype").find("option").hide(); $("#fieldcontexttype").find("optgroup.otherfield").hide(); $("#fieldcontexttype").find("option.floating").show(); $("#fieldcontextsize").parent().hide(); $("#fieldcontextprepend").parent().parent().hide(); $("#fieldcontextprepend").val(""); $("#fieldcontextappend").val(""); $(e).removeAttr("data-append"); $(e).removeAttr("data-prepend"); $("#fieldcontextinputgroup").parent().parent().hide(); if($("#fieldcontextplaceholder").val()=="" ) { $("#fieldcontextplaceholder").val($("#fieldcontextlabel").val()); } } else { $("#fieldcontexttype").find("option").show(); $("#fieldcontextsize").closest("."+$(e).attr("data-form")).show(); $("#fieldcontexttype").find("optgroup.otherfield").show(); } if($(e).attr("data-form")!="range") { if($(e).attr("data-form")=="radio") { $("#fieldcontextmin").attr("type","text"); } else { if($(e).attr("data-form")!="checkbox") { $("#fieldcontextmin").attr("type",$(e).attr("data-form")); $("#fieldcontextmax").attr("type",$(e).attr("data-form")); $("#fieldcontextdefault").attr("type",$(e).attr("data-form")); } } } else { $("#fieldcontextmin").attr("type","number"); $("#fieldcontextmax").attr("type","number"); } if($(e).attr("data-form")=="date" || $(e).attr("data-form")=="datetime-local" || $(e).attr("data-form")=="time") { if(typeof $(e).attr("data-min-formula")!="undefined" && $(e).attr("data-min-formula")!="") { $("#fieldcontextmin").parent().find("i.fa-function").hide(); $("#fieldcontextmin").hide(); $("#fieldcontextmin").parent().find("i.fa-calendar-days").show(); $("#fieldcontextmin").parent().find(".formulabutton").show(); } else { $("#fieldcontextmin").parent().find("i.fa-function").show(); $("#fieldcontextmin").show(); $("#fieldcontextmin").parent().find("i.fa-calendar-days").hide(); $("#fieldcontextmin").parent().find(".formulabutton").hide(); } if(typeof $(e).attr("data-max-formula")!="undefined" && $(e).attr("data-max-formula")!="") { $("#fieldcontextmax").parent().find("i.fa-function").hide(); $("#fieldcontextmax").hide(); $("#fieldcontextmax").parent().find("i.fa-calendar-days").show(); $("#fieldcontextmax").parent().find(".formulabutton").show(); } else { $("#fieldcontextmax").parent().find("i.fa-function").show(); $("#fieldcontextmax").show(); $("#fieldcontextmax").parent().find("i.fa-calendar-days").hide(); $("#fieldcontextmax").parent().find(".formulabutton").hide(); } if(typeof $(e).attr("data-default-formula")!="undefined" && $(e).attr("data-default-formula")!="") { $("#fieldcontextdefault").parent().find("i.fa-function").hide(); $("#fieldcontextdefault").hide(); $("#fieldcontextdefault").parent().find("i.fa-calendar-days").show(); $("#fieldcontextdefault").parent().find(".formulabutton").show(); } else { $("#fieldcontextdefault").parent().find("i.fa-function").show(); $("#fieldcontextdefault").show(); $("#fieldcontextdefault").parent().find("i.fa-calendar-days").hide(); $("#fieldcontextdefault").parent().find(".formulabutton").hide(); } $("#fieldcontextbody #fieldcontextmin").parent().find("i.fa-function,.formulabutton").on("click",function() { minmaxfunction(e,"Min",document.getElementById('fieldcontexttype').value); }); $("#fieldcontextbody #fieldcontextdefault").parent().find("i.fa-function,.formulabutton").on("click",function() { minmaxfunction(e,"Default",document.getElementById('fieldcontexttype').value); }); $("#fieldcontextbody #fieldcontextmax").parent().find("i.fa-function,.formulabutton").on("click",function() { minmaxfunction(e,"Max",document.getElementById('fieldcontexttype').value); }); $("#fieldcontextbody #fieldcontextdefault").parent().find("i.fa-calendar-days").on("click",function() { $(e).removeAttr("data-default-formula"); $(e).removeAttr("data-default-formula-custom"); getcontext(e); }); $("#fieldcontextbody #fieldcontextmin").parent().find("i.fa-calendar-days").on("click",function() { $(e).removeAttr("data-min-formula"); $(e).removeAttr("data-min-formula-custom"); getcontext(e); }); $("#fieldcontextbody #fieldcontextmax").parent().find("i.fa-calendar-days").on("click",function() { $(e).removeAttr("data-max-formula"); $(e).removeAttr("data-max-formula-custom"); getcontext(e); }); } } function checkurl(type,url) { docheckurl(type,url) .then ((data) => { return "OK"; }) .catch((error) => { return error.status; }); } function docheckurl(type,url) { return new Promise((resolve,reject) => { $.ajax({ method:type, url:url}).done(function() { resolve("OK") ; }).fail(function(e) { reject(e); }); }); } function docontext(c,a,b) { e=event; dirty(); var response; if(typeof $(a).data("component")!="undefined" ) { a.value=a.value.trim(); components=JSON.parse($(a).data("component").replaceAll("'",'"')); attributes=JSON.parse($(a).data("attr").replaceAll("'",'"')); $(components).each(function(x,y) { if(typeof $(a).data("valid")!="undefined") { var valid=JSON.parse($(a).data("valid").replaceAll("'",'"')); $(valid).each(function(i,j) { if(j=="geturl" && a.value!="") { if(a.validity.valid==false) { messagepop("The value entered is not a valid URL. Please provide the full URL including https://","exclamation-circle"); return false; } docheckurl("get",a.value).then((data) => { }).catch((error) => { if(error.status>0) { messagepop("The URL provided returned a "+ error.status + " error when a GET request was attempted.

    The URL will be retained as it is appreciated you may not have created the script yet.","bug") } else { messagepop("The URL provided returned an undefined error when a GET request was attempted. For more information, inspect the browser's console.

    The URL will be retained as it is appreciated you may not have created the script yet.","bug"); } }); } if(j=="posturl" && a.value!="") { if(a.validity.valid==false) { messagepop("The value entered is not a valid URL. Please provide the full URL including https://","exclamation-circle"); return false; } docheckurl("post",a.value).then((data) => { }).catch((error) => { if(error.status>0) { messagepop("The URL provided returned a "+ error.status + " error when a POST request was attempted.

    The URL will be retained as it is appreciated you may not have created the script yet.","bug") } else { messagepop("The URL provided returned an undefined error when a POST request was attempted. For more information, inspect the browser's console.

    The URL will be retained as it is appreciated you may not have created the script yet.","bug"); } }); } if(j=="usspaces" && a.value!="") { a.value=a.value.replaceAll(" ","-").trim(); } if(j=="whitespace" && a.value!="") { a.value=a.value.replaceAll(/[\n]+/g,"\n"); } if(j=="tolower" && a.value!="") { a.value=a.value.toLocaleLowerCase(); } if(j=="unique" && a.value!="") { if( $("#formcontainer").find("div["+attributes[0] +" ='"+a.value + "']").not($(b)).length>0) { messagepop("The value of
    "+ $(a).siblings("label").text() + "
    must be unique.

    The value " + a.value + " is already in use on component #"+ $("#formcontainer").find("div["+attributes[0] +" ='"+a.value + "']").not($(b)).eq(0).attr("id") + "

    Please try again","exclamation-circle"); $(a).val(""); return false; } } if(j=="alphanum" && a.value!="") { var r=new RegExp(/^[a-zA-Z0-9-]+$/); if(r.test(a.value)==false) { messagepop("Only letters, numbers and hyphens are permitted in
    " + $(a).siblings("label").text() + "

    Invalid characters have been removed. Please check the santised entry.","exclamation-circle"); $(a).val( $(a).val().replace(/[^a-zA-Z0-9-]/g,"").trim() ); return false; } } if(j=="regexp" && a.value!="") { try { r=new RegExp(a.value,"v"); } catch(err) { messagepop("The pattern entered could not be evaluated as a valid regular expression.

    Please do not use delimiters. These are added automatically.

    The pattern is compiled using the \"v\" flag. Get more information about how this influences how the pattern should be constructed.

    Please try again.","exclamation-circle"); } } }); } if(y=="this") { z=$(b).eq(0); } else { z=$(b).find(y).eq(0); } if(z.length>0) { if($(a).attr("type")=="checkbox") { $(z).attr(attributes[x],a.checked); } else { if(attributes[x]=="html") { $(z).html(a.value); if(a.value) { $(z).removeClass("d-none"); } else { $(z).addClass("d-none"); } } else { if(attributes[x]=="class") { if(typeof $(a).attr("data-class-remove")!="undefined") { $(z).removeClass($(a).attr("data-class-remove")); } $(z).addClass(a.value); } else { $(z).attr(attributes[x],a.value); } } } } }); } if($(a).data("fn")) { if(typeof setcontextfunction[$(a).data("fn")]=="function") { setcontextfunction[$(a).data("fn")](a,b,context); } } else { if(c=="field") { checkfield(b); } } } function optionsmoved(field) { dirty(); $("#fieldcontextoptions").find("input").attr("disabled",true); if($(field).attr("data-form")=="select") { $(field).find("select").html(""); $("#fieldcontextoptions").find("tr").each(function() { $(field).find("select").append(``); }); } else { z=0; $(field).find(".checks").html(""); $("#fieldcontextoptions").find("tr").each(function() { $(field).find(".checks").append(`
    `); z++; }); } $("#fieldcontextoptions").find("input").attr("disabled",false); } function unsortable(elem) { if($(elem).hasClass("ui-sortable")) { $(elem).removeClass("ui-sortable"); $(elem).sortable("destroy"); //call widget-function destroy } } function getselectedclass(id,e,prefix,notfound) { found=false; $(id).find("option").each(function() { if($(e).hasClass(prefix+this.value)) { found=this.value; } }) if(found) { return found; } else { return notfound; } } function getcolumnclass(ele, find) { if (find == "xs") { tfind = "col-" } else { tfind = "col-" + find + "-" } for (i = 1; i <= 12; i++) { if (ele.hasClass(tfind + i)) { return i } } if (find == "xs") { return "auto" } else { return "inherit" } } function orderdown(p) { dstart = $("#fieldcontextbody #fieldcontextoptions").find(".descriptor").eq(p).val(); dswap = $("#fieldcontextbody #fieldcontextoptions").find(".descriptor").eq(p + 1).val(); vstart = $("#fieldcontextbody #fieldcontextoptions").find(".value").eq(p).val(); vswap = $("#fieldcontextbody #fieldcontextoptions").find(".value").eq(p + 1).val(); $("#fieldcontextbody #fieldcontextoptions").find(".descriptor").eq(p).val(dswap); $("#fieldcontextbody #fieldcontextoptions").find(".descriptor").eq(p + 1).val(dstart); $("#fieldcontextbody #fieldcontextoptions").find(".value").eq(p).val(vswap); $("#fieldcontextbody #fieldcontextoptions").find(".value").eq(p + 1).val(vstart); $("#fieldcontextbody #fieldcontextoptions").find(".descriptor").eq(p).trigger("keyup"); $("#fieldcontextbody #fieldcontextoptions").find(".descriptor").eq(p + 1).trigger("keyup"); $("#fieldcontextbody #fieldcontextoptions").find(".value").eq(p).trigger("keyup"); $("#fieldcontextbody #fieldcontextoptions").find(".value").eq(p + 1).trigger("keyup") } function orderup(p) { dstart = $("#fieldcontextbody #fieldcontextoptions").find(".descriptor").eq(p).val(); dswap = $("#fieldcontextbody #fieldcontextoptions").find(".descriptor").eq(p - 1).val(); vstart = $("#fieldcontextbody #fieldcontextoptions").find(".value").eq(p).val(); vswap = $("#fieldcontextbody #fieldcontextoptions").find(".value").eq(p - 1).val(); $("#fieldcontextbody #fieldcontextoptions").find(".descriptor").eq(p).val(dswap); $("#fieldcontextbody #fieldcontextoptions").find(".descriptor").eq(p - 1).val(dstart); $("#fieldcontextbody #fieldcontextoptions").find(".value").eq(p).val(vswap); $("#fieldcontextbody #fieldcontextoptions").find(".value").eq(p - 1).val(vstart); $("#fieldcontextbody #fieldcontextoptions").find(".descriptor").eq(p).trigger("keyup"); $("#fieldcontextbody #fieldcontextoptions").find(".descriptor").eq(p - 1).trigger("keyup"); $("#fieldcontextbody #fieldcontextoptions").find(".value").eq(p).trigger("keyup"); $("#fieldcontextbody #fieldcontextoptions").find(".value").eq(p - 1).trigger("keyup") } function updateoptions(id, ele) { if ($("#" + id).data("form") == "select") { if ($(ele).hasClass("value")) { $("#" + id).find("option").eq($(ele).data("entry")).val($(ele).val()) } if ($(ele).hasClass("descriptor")) { $("#" + id).find("option").eq($(ele).data("entry")).html($(ele).val()) } } else { if ($(ele).hasClass("value")) { $("#" + id).find(".checks").find("input").eq($(ele).data("entry")).val($(ele).val()) } if ($(ele).hasClass("descriptor")) { $("#" + id).find(".checks").find("label").eq($(ele).data("entry")).html($(ele).val()) } } } function addoption(ele,loc) { dirty(); if(typeof loc=="undefined") { loc="bottom"; } if(loc=="bottom") { $("#fieldcontextoptions").append(`  `); } else { $("#fieldcontextoptions").prepend(`  `); } $("#fieldcontextoptions").find("i.fa-trash-can").off(); $("#fieldcontextoptions").find("i.fa-trash-can").on("click",function() { deleteoption(this,ele); }); optionsreindex(ele); } function deleteoption(item,ele) { dirty(); $(item).closest("tr").remove(); optionsreindex(ele); } function addcheck(check, type) { that = check; if (type == 1) { $(check).parent().parent().find(".checks").append("
    ") } else { $(check).parent().parent().find(".checks").append("
    ") } propagate(true) } function designform(formid) { $.ajax({ method: "GET", url: "/forms/edit.php", data: { subsubfolder: formid } }).done(function(msg) { document.getElementById("formcontainer").innerHTML = msg; initsort(formid) }) } function initialise(formid, callback) { if (document.getElementById("form-" + formid)) { $('#form-' + formid + ' input,#form-' + formid + ' textarea,#form-' + formid + ' select').filter('[required]:not(:disabled)').css({ "borderColor": "red", "border-style": "dotted" }); toolovers(); $('#form-' + formid).on('keyup change paste', '.form-' + formid, function() { document.getElementById('dirty-' + formid).value = "yes" }); if (document.getElementById("fc-script-" + formid)) { jQuery.globalEval(document.getElementById("fc-script-" + formid).innerHTML) } if (document.getElementById("autosave-" + formid)) { jQuery.globalEval(document.getElementById("autosave-" + formid).innerHTML) } if (document.getElementById("inlinescripts-" + formid)) { jQuery.globalEval(document.getElementById("inlinescripts-" + formid).innerHTML) } if (typeof callback == "function") { callback() } $("#form-" + formid).submit(function(event) { event.preventDefault() }) } else { return false } } function getalignment(formcomponent, context) { var align = {}; var size = {}; size = { "xs": "", "sm": "sm-", "md": "md-", "lg": "lg-", "xl": "xl-", "xxl": "xxl-" }; align.start = "start"; align.end = "end"; align.center = "center"; align.start = "start"; var newclass = ""; $.each(size, function(sindex, svalue) { $.each(align, function(aindex, avalue) { if ($("#" + formcomponent).hasClass("text-" + svalue + aindex)) { $("#" + context + "align" + sindex).val("text-" + svalue + avalue) } }); $("#" + context + "align" + sindex).on("change", function() { $("#" + formcomponent).removeClass("text-" + svalue + "start text-" + svalue + "center text-" + svalue + "end"); $("#" + formcomponent).addClass(this.value) }) }) } function getwidth(formcomponent, context, parent) { var align = {}; var size = {}; size = { "xs": "", "sm": "sm-", "md": "md-", "lg": "lg-", "xl": "xl-", "xxl": "xxl-" }; var newclass = ""; $.each(size, function(sindex, svalue) { if (sindex == "xs") { $("#" + context + "width" + sindex).val("auto") } else { $("#" + context + "width" + sindex).val("inherit") } for (w = 1; w <= 12; w++) { if (parent) { that = $("#" + formcomponent).parent(); if ($("#" + formcomponent).parent().hasClass("col-" + svalue + w)) { $("#" + context + "width" + sindex).val(w) } } else { if ($("#" + formcomponent).hasClass("col-" + svalue + w)) { $("#" + context + "width" + sindex).val(w) } } } ele = "#" + context + "width" + sindex; $(ele).on("change", eventhandler(context, that, sindex, svalue)) }) } function getmargin(e,context) { var side = {}; side = { "top": "mt-", "bottom": "mb-", "start": "ms-", "end": "me-", }; var newclass=""; $.each(side,function(sindex,svalue) { $("#"+context+"margin"+sindex).on("change",function() { $(e).removeClass(svalue+"1 "+svalue+"2 "+ svalue+"3 "+svalue+"4 "+svalue+"5"); $(e).addClass(svalue+this.value); }); for (m = 0; m <= 5; m++) { if($(e).hasClass(svalue+m)) { $("#"+context+"margin"+sindex).val(m); } } }); } function getmarginold(formcomponent, context, parent) { var side = {}; side = { "top": "mt-", "bottom": "mb-", "start": "ms-", "end": "me-", }; var newclass = ""; $.each(side, function(sindex, svalue) { for (m = 0; m <= 5; m++) { if (parent) { that = $("#" + formcomponent).parent(); if ($("#" + formcomponent).parent().hasClass(svalue + m)) { $("#" + context + "margin" + sindex).val(m) } } else { if ($("#" + formcomponent).hasClass(svalue + m)) { $("#" + context + "margin" + sindex).val(m) } } } $("#" + context + "margin" + sindex).on("change", function() { $("#" + formcomponent).removeClass(svalue + "0 " + svalue + "1 " + svalue + "2 " + svalue + "3 " + svalue + "4 " + svalue + "5"); $("#" + formcomponent).addClass(svalue + this.value) }) }) } function eventhandler(context, component, index, value) { return function(event) { if (index == "xs") { $(component).removeClass("col") } $(component).removeClass("col-" + value + "1 col-" + value + "2 col-" + value + "3 col-" + value + "4 col-" + value + "5 col-" + value + "6 col-" + value + "7 col-" + value + "7 col-" + value + "8 col-" + value + "9 col-" + value + "10 col-" + value + "11 col-" + value + "12"); if (document.getElementById(context + "width" + index).value == "auto") { $(component).addClass("col") } else { if (document.getElementById(context + "width" + index).value == "inherit") {} else { $(component).addClass("col-" + value + document.getElementById(context + "width" + index).value) } } } } function checkstorage(key) { if (localStorage.getItem(key)) { return true } else { return false } } function getstorage(key) { if (localStorage.getItem(key)) { return localStorage.getItem(key) } else { return false } } function setstorage(key, value) { if (localStorage.setItem(key, value)) { localStorage.getItem(key) } else { return false } } function addfirstfield() { $(".start").toggle(); $("#home").addClass("d-none"); $("#fullform").removeClass("d-none"); $("#formcontainer").attr("data-id","yourform"); $("#formcontainer").attr("data-name","Your Form"); $("#formcontainer").append(`

    `); $.ajax({ method:"POST", url:"/newform.php", }); propagate(true); countpages(); checksession(); dirty(); getcontext(document.getElementById("fullform")); } function download() { $("#popupModal").modal("hide"); json=JSON.parse(localStorage.getItem("formstrapjson")); if(localStorage.getItem("selfhosttandc")==null) { messagepop("Please review the Terms of Use first","signature",function() { tandcpop() },function() { return false},"Terms of Use","Cancel"); return false; } if(json["layout"]["Form"]["SuccessURL"]=="" || typeof json["layout"]["Form"]["SuccessURL"]=="undefined") { messagepop("You must specify the URL the browser will redirect to when the form has successfully been submitted by the user.

    Please do this first in Form Settings.","exclamation-circle",function() { getcontext(document.getElementById("fullform"));$("#popupModal").modal("hide");setTimeout(function() { $("#formcontextsuccessurl").focus(); },1000); },function() { return false; },"Settings","Cancel"); return false; } if(json["layout"]["Form"]["FailureURL"]=="" || typeof json["layout"]["Form"]["FailureURL"]=="undefined") { messagepop("You must specify the URL the browser will redirect to when the form submission is rejected by the server.

    Please do this first in Form Settings.","exclamation-circle",function() { getcontext(document.getElementById("fullform"));$("#popupModal").modal("hide");setTimeout(function() { $("#formcontextfailureurl").focus(); },1000); },function() { return false; },"Settings","Cancel"); return false; } if(json["layout"]["Form"]["POSTURL"]=="" || typeof json["layout"]["Form"]["POSTURL"]=="undefined") { messagepop("You must specify the URL of the server-side script that will process the form submission.

    Please do this first in Form Settings.","exclamation-circle",function() { getcontext(document.getElementById("fullform"));$("#popupModal").modal("hide");setTimeout(function() { $("#formcontextposturl").focus(); },1000); },function() { return false; },"Settings","Cancel"); return false; } if($("#formcontainer").find(".form-group").length==0) { messagepop("Your form has no fields","exclamation-circle"); return false; } if(localStorage.getItem("formstrapjson")=="") { messagepop("You have unsaved changes. Please save your form first","exclamation-circle"); return false; } if($("#formcontainer").attr("data-name")=="" || typeof $("#formcontainer").attr("data-name")=="undefined") { messagepop("You must give your form a name.

    Please do this first in Form Settings.","exclamation-circle",function() { getcontext(document.getElementById("fullform"));$("#popupModal").modal("hide");setTimeout(function() { $("#formcontextname").focus(); },1000); },function() { return false; },"Settings","Cancel"); return false; } json=serialiseform(); $.ajax({ method:"post", url:"/scripts/package.php", dataType:"json", data:{formdata:JSON.stringify(json)} }).done(function(msg) { if(msg.response=="OK") { imagehtml=""; if(json["layout"]["Form"]["Heading"]["logo"]["src"]) { filename=json["layout"]["Form"]["Heading"]["logo"]["src"].split("/"); imagehtml=`images ` + filename[filename.length-1] +``; } setTimeout(function() { location.href=msg.url; },1500); $("#popupModal").find(".modal-header").removeClass("d-none"); $("#popupModal").find(".modal-header").html(` `); $("#popupdia").removeClass("modal-sm modal-md"); $("#popupdia").addClass("modal-lg"); i $("#popupbod").html(`

    A zip file has been downloaded to your computer.

    This contains most of the files you need to publish your form. You need to create the script that processes the form and the pages for success/failure redirects.

    The "readme.pdf" file provides more detail about each file and deployment instructions.

    If you are unable to self-host the form please consider creating an acount or logging in and hosting with formstrap for a small "pay as you go" fee.

    If you successfully self-host and are happy with the result please consider making an affordable donation to support the free self-hosting service. All contributions are very gratefully received.

    What's in the zip file?
    `+imagehtml+`
    ` + msg.filename + `
    css
    selfhost.css
    font
    EduVICWANTBeginner-Regular.ttf
    OFL.txt
    js
    easing.js
    events.js
    selfhost.js
    strtotime.js
    favicon.png
    form.html
    index.html
    readme.pdf

    `); setTimeout(function() { $("#popupModal").modal("show"); },1000); toolovers(); } else { messagepop("There was a problem creating your form","bug"); } }).fail(function(msg) { messagepop("There was a problem creating your form","bug"); }); } function donateoutcome(outcome,icon,colour) { messagepop(outcome,icon,null,null,null,null,null,null,null,colour); } function donate() { location.href="https://www.paypal.com/donate/?hosted_button_id=PAFGYQZ6AJM3A"; } function paypaliframe() { if($("#donationce").val()<1) { $("#donateerror").html("The minimum donation that we can accept is £1.00"); $("#donationce").val("1"); $("#donationce").trigger("blur"); $("#donationce").focus(); return false; } $("#ganopay").prop("disabled",true); $("#ganopay").html(` Creating PayPal Order`); $.ajax({ method:"POST", url:"/scripts/donate.php", data:{amount:$("#donationce").val(),name:$("#donatename").val(),note:$("#donatenote").val(),fee:$("#feetick").prop("checked")}, dataType:"json" }).done(function(msg) { if(msg.status=="PAYER_ACTION_REQUIRED") { $("#popupModal").find(".modal-header").html(``); $("#popupbod").html(`

    Your Donation Order has successfully been created by PayPal.

    One off donation£`+msg.amount+`
    Total to be Paid£`+msg.amount+`

    Click the button below to visit PayPal and authorise the payment.

    Please note you do not need to have a PayPal account to donate with PayPal.

    `); } }) } function formsettings() { unselect(); $("#offcanvascontext").removeClass("offcanvas-start"); $("#offcanvascontext").addClass("offcanvas-end"); $("#offcanvasevents").removeClass("offcanvas-start"); $("#offcanvasevents").addClass("offcanvas-end"); getcontext(document.getElementById("fullform")); } function viewdemo() { messagepop(`

    The form will open in a new window or tab. It is a fully functioning, formstrap-hosted form. You can complete the form and the data you enter will be submitted. Please don\'t use real information (though if you want to see how the form-to-pdf function works you\'ll need to enter a real email address).

    The form only works if accessed from the buttons below as a referrer restriction has been added to the form.

    Do you want to proceed? You can choose to view an empty form or one that has been completed (the data is about a fictional person - any similarity to a real person is entirely coincidental).

    `,`question-circle`,function() { getdemonodata(); },function() { getdemowithdata(); },`View Empty Form`,`View Completed Form`,true,`modal-md`,null,`green`,null,`primary`,`primary`); } function getdemowithdata() { $.ajax({ method:"POST", url:"/scripts/sampledata.php", dataType:"json" }).done(function(msg) { if(msg.response=="OK") { localStorage.setItem("demoapplication-data",msg.data); window.open(`https://formstrap.com/samples/DemoForm`,`demo`); } }); } function getdemonodata() { $.ajax({ method:"POST", url:"/scripts/sampledata.php", dataType:"json" }).done(function(msg) { if(msg.response=="OK") { localStorage.removeItem("demoapplication-data"); window.open(`https://formstrap.com/samples/DemoForm`,`demo`); } }); } function getdemoform() { localStorage.removeItem("sampleform-data"); messagepop("The Demonstration Job Application Form will be loaded into the designer.

    The form's metadata will be saved to your browser's local storage.

    Are you sure you want to edit a fresh copy of the demo form?","circle-question",function() { $.ajax({ method:"POST", url:"/scripts/getdemo.php", dataType:"json" }).done(function(msg) { localStorage.setItem("formstrap",msg.HTML); localStorage.setItem("formstrapjson",msg.JSON); localStorage.setItem("name",msg.Name); localStorage.setItem("events",msg.Events); location.href="#" location.reload(); }); },function() { return false; },"Yes","No",null,null,null,"green"); } function getsamplerform() { localStorage.removeItem("sampleform-data"); messagepop("The Sampler Form will be loaded into the designer.

    The form's metadata will be saved to your browser's local storage.

    Are you sure you want to edit a fresh copy of the sampler form?","circle-question",function() { $.ajax({ method:"POST", url:"/scripts/getdemo.php", data:{sampler:"true"}, dataType:"json" }).done(function(msg) { localStorage.setItem("formstrap",msg.HTML); localStorage.setItem("formstrapjson",msg.JSON); localStorage.setItem("name",msg.Name); localStorage.setItem("events",msg.Events); location.href="#"; location.reload(); }); },function() { return false; },"Yes","No",null,null,null,"green"); } function checksession() { $.ajax({ url:"/scripts/checksession.php", method:"POST" }).done(function(msg) { document.getElementById("checksession").value=msg; if(msg!="OK") { $("#navcont").html(``); } else { $("#navcont").html(``); } if(document.getElementById("dirty").value=="yes") { dirty(); } if($("#home").is(":visible")) { $("#navcont").find(".previewmenu").hide(); } else { $("#navcont").find(".previewmenu").show(); } }); } function defined(v,prefix,suffix) { if(typeof prefix=="undefined") { prefix=""; } if(typeof suffix=="undefined") { suffix=""; } if(typeof v!="undefined" && typeof v!="") { return prefix+v+suffix; } else { return ""; } } function getclass(component,container) { classlist=[]; if(container==1 || container==3) { classlist[0]="data-width-xs"; classlist[1]="data-width-sm"; classlist[2]="data-width-md"; classlist[3]="data-width-lg"; classlist[4]="data-width-xl"; classlist[5]="data-width-xxl"; classlist[6]="data-align"; classlist[7]="data-align-sm"; classlist[8]="data-align-md"; classlist[9]="data-align-lg"; classlist[10]="data-align-xl"; classlist[11]="data-align-xxl"; classlist[12]="data-mt"; classlist[13]="data-me"; classlist[14]="data-mb"; classlist[15]="data-ms"; } if(container==2) { classlist[0]="data-pt"; classlist[1]="data-pe"; classlist[2]="data-pb"; classlist[3]="data-ps"; } if(container==3) { classlist[16]="data-pt"; classlist[17]="data-pe"; classlist[18]="data-pb"; classlist[19]="data-ps"; } classesfound=""; $.each(classlist,function(i,v) { classesfound=(classesfound.trim()+" "+defined($(component).attr(v))).trim() }); return classesfound; } function preparebuild(id) { p=1; $("#metadata").get(0).reset(); $("#section0").remove(); $("#formcontextdescription").val(""); $("#formcontextlogo").val(""); $("#formcontextdescription").html(""); $("#formcontextdescription").trigger("change"); $("#formcontextlogo").trigger("change") $("#formtitle").addClass("d-none"); $("#formtitle").removeClass("d-block"); $("#formtitle").html(""); $("#formdescription").removeClass("d-block"); $("#formdescription").html(""); $("#formlogo").attr("src",""); $("#formlogocontainer").removeClass("d-block"); $("#formlogocontainer").addClass("d-none"); $("#formlogocontainer").removeAttr("class"); $("#formintrocontainer").removeAttr("class"); $("#formlogocontainer").removeData("width-xs width-sm width-md width-lg width-xl width-xxl"); $("#formlogocontainer").removeAttr("data-width-xs data-width-sm data-width-md data-width-lg data-width-xl data-width-xxl"); $("#formintroontainer").removeAttr("data-width-xs data-width-sm data-width-md data-width-lg data-width-xl data-width-xxl"); $("#formintrocontainer").removeData("width-xs width-sm width-md width-lg width-xl width-xxl"); buildfields={}; $.ajax({ method:"POST", url:"/scripts/getbuildjson.php", data:{id:id}, dataType:"json" }).done(function(msg) { buildfields["form"]={}; $("#formcontextbody").find("input,select,textarea").each(function(a,b) { buildfields["form"][$(b).attr("id")]=$(b).val(); }); buildfields["section"]={}; $("#sectioncontextbody").find("input,select,textarea").each(function(a,b) { buildfields["section"][$(b).attr("id")]=$(b).val(); }); buildfields["sectioncolumn"]={}; $("#sectioncolumncontextbody").find("input,select,textarea").each(function(a,b) { buildfields["sectioncolumn"][$(b).attr("id")]=$(b).val(); }); buildfields["row"]={}; $("#rowcontextbody").find("input,select,textarea").each(function(a,b) { buildfields["row"][$(b).attr("id")]=$(b).val(); }); buildfields["column"]={}; $("#columncontextbody").find("input,select,textarea").each(function(a,b) { buildfields["column"][$(b).attr("id")]=$(b).val(); }); buildfields["field"]={}; $("#fieldcontextbody").find("input,select,textarea").each(function(a,b) { if($(b).attr("type")=="checkbox") { buildfields["field"][$(b).attr("id")]=b.checked; } else { buildfields["field"][$(b).attr("id")]=$(b).val(); } }); json=JSON.parse(msg.json); layout=json.layout; fields=json.fields; schedule={}; schedule["form"]=[]; schedule["form"].push({"add":"form"}); if(layout["Form"]["Name"] && layout["Form"]["Name"]!=buildfields["form"]["formcontextname"]) { schedule["form"].push({"field":"#formcontextname","value":layout["Form"]["Name"]}); } if(layout["Form"]["ID"] && layout["Form"]["ID"]!=buildfields["form"]["formcontextid"]) { schedule["form"].push({"field":"#formcontextid","value":layout["Form"]["ID"]}); } if(layout["Form"]["SaveToLocal"] && layout["Form"]["SaveToLocal"]!=buildfields["form"]["formcontextsave"]) { schedule["form"].push({"field":"#formcontextsave","value":layout["Form"]["SaveToLocal"]}); } if(layout["Form"]["SaveOpt"] && layout["Form"]["SaveOpt"]!=buildfields["form"]["formcontextsaveopt"]) { schedule["form"].push({"field":"#formcontextsaveopt","value":layout["Form"]["SaveOpt"]}); } if(layout["Form"]["Colour"] && layout["Form"]["Colour"]!=buildfields["form"]["formcontextpagecolour"]) { schedule["form"].push({"field":"#formcontextpagecolour","value":layout["Form"]["Colour"]}); } if(layout["Form"]["TextColour"] && layout["Form"]["TextColour"]!=buildfields["form"]["formcontexttextcolour"]) { schedule["form"].push({"field":"#formcontexttextcolour","value":layout["Form"]["TextColour"]}); } if(layout["Form"]["Class"]) { classes=layout["Form"]["Class"].split(" "); $.each(classes,function(a,b) { type=b.split("-"); if(type.length<3) { if(b && b!=buildfields["form"]["formcontextcontainercontextwidthxs"]) { schedule["form"].push({"field":"#formcontextcontainercontextwidthxs","value":b}); } } if(type.length==3) { if(b && b!=buildfields["form"]["formcontextcontainercontextwidth"+type[1]]) { schedule["form"].push({"field":"#formcontextcontainercontextwidth"+type[1],"value":b}); } } }); } if(layout["Form"]["Heading"]["logo"]["containerclasses"]) { classes=layout["Form"]["Heading"]["logo"]["containerclasses"].split(" "); $.each(classes,function(a,b) { type=b.split("-"); if(type.length<3) { if(b && b!=buildfields["form"]["formcontextlogocontextwidthxs"]) { schedule["form"].push({"field":"#formcontextlogocontextwidthxs","value":b}); } } if(type.length==3) { if(b && b!=buildfields["form"]["formcontextlogocontextwidth"+type[1]]) { schedule["form"].push({"field":"#formcontextlogocontextwidth"+type[1],"value":b}); } } }); } if(layout["Form"]["Heading"]["logo"]["src"] && layout["Form"]["Heading"]["logo"]["src"]!=buildfields["form"]["formcontextlogo"]) { schedule["form"].push({"field":"#formcontextlogo","value":layout["Form"]["Heading"]["logo"]["src"]}); } if(layout["Form"]["Heading"]["logo"]["alt"] && layout["Form"]["Heading"]["logo"]["alt"]!=buildfields["form"]["formcontextlogoalt"]) { schedule["form"].push({"field":"#formcontexttextlogoalt","value":layout["Form"]["Heading"]["logo"]["alt"]}); } if(layout["Form"]["Heading"]["logo"]["icon"] && layout["Form"]["Heading"]["logo"]["icon"]!=buildfields["form"]["formcontextfavicon"]) { schedule["form"].push({"field":"#formcontextfavicon","value":layout["Form"]["Heading"]["logo"]["icon"]}); } if(layout["Form"]["Heading"]["text"]["containerclasses"]) { classes=layout["Form"]["Heading"]["text"]["containerclasses"].split(" "); $.each(classes,function(a,b) { type=b.split("-"); if(type.length<3) { if(b && b!=buildfields["form"]["formcontexttextcontextwidthxs"]) { schedule["form"].push({"field":"#formcontexttextcontextwidthxs","value":b}); } } if(type.length==3) { if(b && b!=buildfields["form"]["formcontexttextcontextwidth"+type[1]]) { schedule["form"].push({"field":"#formcontexttextcontextwidth"+type[1],"value":b}); } } }); } if(layout["Form"]["Heading"]["text"]["title"]["text"] && layout["Form"]["Heading"]["text"]["title"]["text"]!=buildfields["form"]["formcontexttitle"]) { schedule["form"].push({"field":"#formcontexttitle","value":layout["Form"]["Heading"]["text"]["title"]["text"]}); } if(layout["Form"]["Heading"]["text"]["title"]["classes"]) { classes=layout["Form"]["Heading"]["text"]["title"]["classes"].replaceAll("m-0 p-0 ","").split(" "); $.each(classes,function(a,b) { type=b.split("-"); if(type.length<3) { if(b && b!=buildfields["form"]["formcontexttitlecontextalignxs"]) { schedule["form"].push({"field":"#formcontexttitlecontextalignxs","value":b}); } } if(type.length==3) { if(b && b!=buildfields["form"]["formcontexttitlecontextalign"+type[1]]) { schedule["form"].push({"field":"#formcontexttitlecontextalign"+type[1],"value":b}); } } }); } if(layout["Form"]["Heading"]["text"]["description"]["text"] && layout["Form"]["Heading"]["text"]["description"]["text"]!=buildfields["form"]["formcontextdescription"]) { schedule["form"].push({"field":"#formcontextdescription","value":layout["Form"]["Heading"]["text"]["description"]["text"]}); } if(layout["Form"]["Heading"]["text"]["description"]["renderHTML"] && layout["Form"]["Heading"]["text"]["description"]["renderHTML"]!=buildfields["form"]["formcontextdescriptionhtml"]) { schedule["form"].push({"field":"#formcontextdescriptionhtml","value":layout["Form"]["Heading"]["text"]["description"]["renderHTML"]}); } if(layout["Form"]["Heading"]["text"]["description"]["classes"]) { classes=layout["Form"]["Heading"]["text"]["description"]["classes"].replaceAll("m-0 p-0 ","").split(" "); $.each(classes,function(a,b) { type=b.split("-"); if(type.length<3) { if(b && b!=buildfields["form"]["formcontextdescriptioncontextalignxs"]) { schedule["form"].push({"field":"#formcontextdescriptioncontextalignxs","value":b}); } } if(type.length==3) { if(b && b!=buildfields["form"]["formcontextdescriptioncontextalign"+type[1]]) { schedule["form"].push({"field":"#formcontextdescriptioncontextalign"+type[1],"value":b}); } } }); } if(layout["Form"]["Pagination"]["Scroll"] && layout["Form"]["Pagination"]["Scroll"]!=buildfields["form"]["formcontextpaginationscroll"]) { schedule["form"].push({"field":"#formcontextpaginationscroll","value":layout["Form"]["Pagination"]["Scroll"]}); } if(layout["Form"]["Pagination"]["Position"] && layout["Form"]["Pagination"]["Position"]!=buildfields["form"]["formcontextpaginationposition"]) { schedule["form"].push({"field":"#formcontextpaginationposition","value":layout["Form"]["Pagination"]["Position"]}); } if(layout["Form"]["Pagination"]["Submit"] && layout["Form"]["Pagination"]["Submit"]!=buildfields["form"]["formcontextpaginationsubmit"]) { schedule["form"].push({"field":"#formcontextpaginationsubmit","value":layout["Form"]["Pagination"]["Submit"]}); } if(layout["Form"]["Pagination"]["Format"] && layout["Form"]["Pagination"]["Format"]!=buildfields["form"]["formcontextpagination"]) { schedule["form"].push({"field":"#formcontextpagination","value":layout["Form"]["Pagination"]["Format"]}); } $.each(layout["Form"]["Sections"],function(a,b) { secid=b.SystemID; schedule["form"].push({"add":"section","id":b.SystemID}); if(b["Page"] && b["Page"]!=buildfields["section"]["sectioncontextpage"]) { schedule["form"].push({"field":"#sectioncontextpage","value":b["Page"],"delay":3,"id":secid}); } if(b["CustomID"] && b["CustomID"]!=buildfields["section"]["sectioncontextid"]) { schedule["form"].push({"field":"#sectioncontextid","value":b["CustomID"]}); } if(b["CustomClass"] && b["CustomClass"]!=buildfields["section"]["sectioncontextclass"]) { schedule["form"].push({"field":"#sectioncontextclass","value":b["CustomClass"]}); } if(b["Title"] && b["Title"]!=buildfields["section"]["sectioncontexttitle"]) { schedule["form"].push({"field":"#sectioncontexttitle","value":b["Title"]}); } if(b["Description"] && b["Description"]!=buildfields["section"]["sectioncontextdescription"]) { schedule["form"].push({"field":"#sectioncontextdescription","value":b["Description"]}); } if(b["DescriptionHTML"] && b["DescriptionHTML"]!=buildfields["section"]["sectioncontextdescriptionhtml"]) { schedule["form"].push({"field":"#sectioncontextdescriptionhtml","value":b["DescriptionHTML"]}); } if(b["Visible"] && b["Visible"]!=buildfields["section"]["sectioncontextvisible"]) { schedule["form"].push({"field":"#sectioncontextvisible","value":b["Visible"]}); } if(b["Card"] && b["Card"]!=buildfields["section"]["sectioncontextcard"]) { schedule["form"].push({"field":"#sectioncontextcard","value":b["Card"]}); } if(b["CardColour"] && b["CardColour"]!=buildfields["section"]["sectioncontextcardcolour"]) { schedule["form"].push({"field":"#sectioncontextcardcolour","value":b["CardColour"]}); } if(b["Class"]) { classes=b["Class"].split(" "); $.each(classes,function(a,b) { type=b.split("-"); if(type[0]=="mb") { type="bottom"; } if(type[0]=="mt") { type="top"; } if(type[0]=="ms") { type="start"; } if(type[0]=="me") { type="end"; } if(b && b!=buildfields["section"]["sectioncontextmargin"+type]) { schedule["form"].push({"field":"#sectioncontextmargin"+type,"value":b}); } }); } if(b["ContainerClass"]) { classes=b["ContainerClass"].split(" "); $.each(classes,function(a,b) { type=b.split("-"); if(type[0]=="pb") { type="bottom"; } if(type[0]=="pt") { type="top"; } if(type[0]=="ps") { type="start"; } if(type[0]=="pe") { type="end"; } if(b && b!=buildfields["section"]["sectioncontextpadding"+type]) { schedule["form"].push({"field":"#sectioncontextpadding"+type,"value":b}); } }); } if(b["Gutter-X"] && b["Gutter-X"]!=buildfields["section"]["sectioncontextgutterx"]) { schedule["form"].push({"field":"#sectioncontextgutterx","value":b["Gutter-X"]}); } if(b["Gutter-Y"] && b["Gutter-Y"]!=buildfields["section"]["sectioncontextguttery"]) { schedule["form"].push({"field":"#sectioncontextguttery","value":b["Gutter-Y"]}); } $.each(b["SectionColumns"],function(a,b) { schedule["form"].push({"add":"sectioncolumn","id":b.SystemID,"to":secid}); seccolid=b.SystemID; if(b["CustomID"] && b["CustomID"]!=buildfields["sectioncolumn"]["sectioncolumncontextid"]) { schedule["form"].push({"field":"#sectioncolumncontextid","value":b["CustomID"]}); } if(b["CustomClass"] && b["CustomClass"]!=buildfields["sectioncolumn"]["sectioncolumncontextclass"]) { schedule["form"].push({"field":"#sectioncolumncontextclass","value":b["CustomClass"]}); } if(b["Title"] && b["Title"]!=buildfields["sectioncolumn"]["sectioncolumncontexttitle"]) { schedule["form"].push({"field":"#sectioncolumncontexttitle","value":b["Title"]}); } if(b["Description"] && b["Description"]!=buildfields["sectioncolumn"]["sectioncolumncontextdescription"]) { schedule["form"].push({"field":"#sectioncolumncontextdescription","value":b["Description"]}); } if(b["DescriptionHTML"] && b["DescriptionHTML"]!=buildfields["sectioncolumn"]["sectioncolumncontextdescriptionhtml"]) { schedule["form"].push({"field":"#sectioncolumncontextdescriptionhtml","value":b["DescriptionHTML"]}); } if(b["Visible"] && b["Visible"]!=buildfields["sectioncolumn"]["sectioncolumncontextvisible"]) { schedule["form"].push({"field":"#sectioncolumncontextvisible","value":b["Visible"]}); } if(b["Replicable"] && b["Replicable"]!=buildfields["sectioncolumn"]["sectioncolumncontextreplicable"]) { schedule["form"].push({"field":"#sectioncolumncontextreplicable","value":b["Replicable"]}); } if(b["ReplicableAdd"] && b["ReplicableAdd"]!=buildfields["sectioncolumn"]["sectioncolumncontextreplicableadd"]) { schedule["form"].push({"field":"#sectioncolumncontextreplicableadd","value":b["ReplicableAdd"]}); } if(b["ReplicableDelete"] && b["ReplicableDelete"]!=buildfields["sectioncolumn"]["sectioncolumncontextreplicabledelete"]) { schedule["form"].push({"field":"#sectioncolumncontextreplicabledelete","value":b["ReplicableDelete"]}); } if(b["Card"] && b["Card"]!=buildfields["sectioncolumn"]["sectioncolumncontextcard"]) { schedule["form"].push({"field":"#sectioncolumncontextcard","value":b["Card"]}); } if(b["CardColour"] && b["CardColour"]!=buildfields["sectioncolumn"]["sectioncolumncontextcardcolour"]) { schedule["form"].push({"field":"#sectioncolumncontextcardcolour","value":b["CardColour"]}); } if(b["ContainerClass"]) { classes=b["ContainerClass"].split(" "); $.each(classes,function(a,b) { type=b.split("-"); if(type[0]=="pb") { type="bottom"; } if(type[0]=="pt") { type="top"; } if(type[0]=="ps") { type="start"; } if(type[0]=="pe") { type="end"; } if(b && b!=buildfields["sectioncolumn"]["sectioncolumncontextpadding"+type]) { schedule["form"].push({"field":"#sectioncolumncontextpadding"+type,"value":b}); } }); } if(b["Class"]) { classes=b["Class"].split(" "); $.each(classes,function(a,b) { type=b.split("-"); if(type.length<3) { if(b && b!=buildfields["sectioncolumn"]["sectioncolumncontextcontextwidthxs"]) { schedule["form"].push({"field":"#sectioncolumncontextcontextwidthxs","value":b}); } } if(type.length==3) { if(b && b!=buildfields["sectioncolumn"]["sectioncolumncontextcontextwidth"+type[1]]) { schedule["form"].push({"field":"#sectioncolumncontextcontextwidth"+type[1],"value":b}); } } }); } $.each(b["Rows"],function(a,b) { schedule["form"].push({"add":"row","id":b.SystemID,"to":seccolid}); rowid=b.SystemID; if(b["CustomID"] && b["CustomID"]!=buildfields["row"]["rowcontextid"]) { schedule["form"].push({"field":"#rowcontextid","value":b["CustomID"]}); } if(b["CustomClass"] && b["CustomClass"]!=buildfields["row"]["rowcontextclass"]) { schedule["form"].push({"field":"#rowcontextclass","value":b["CustomClass"]}); } if(b["Title"] && b["Title"]!=buildfields["row"]["rowcontexttitle"]) { schedule["form"].push({"field":"#rowcontexttitle","value":b["Title"]}); } if(b["Description"] && b["Description"]!=buildfields["row"]["rowcontextdescription"]) { schedule["form"].push({"field":"#rowcontextdescription","value":b["Description"]}); } if(b["DescriptionHTML"] && b["DescriptionHTML"]!=buildfields["row"]["rowcontextdescriptionhtml"]) { schedule["form"].push({"field":"#rowcontextdescriptionhtml","value":b["DescriptionHTML"]}); } if(b["Visible"] && b["Visible"]!=buildfields["row"]["rowcontextvisible"]) { schedule["form"].push({"field":"#rowcontextvisible","value":b["Visible"]}); } if(b["Replicable"] && b["Replicable"]!=buildfields["row"]["rowcontextreplicable"]) { schedule["form"].push({"field":"#rowcontextreplicable","value":b["Replicable"]}); } if(b["ReplicableAdd"] && b["ReplicableAdd"]!=buildfields["row"]["rowcontextreplicableadd"]) { schedule["form"].push({"field":"#rowcontextreplicableadd","value":b["ReplicableAdd"]}); } if(b["ReplicableDelete"] && b["ReplicableDelete"]!=buildfields["row"]["rowcontextreplicabledelete"]) { schedule["form"].push({"field":"#rowcontextreplicabledelete","value":b["ReplicableDelete"]}); } if(b["Card"] && b["Card"]!=buildfields["row"]["rowcontextcard"]) { schedule["form"].push({"field":"#rowcontextcard","value":b["Card"]}); } if(b["CardColour"] && b["CardColour"]!=buildfields["row"]["rowcontextcardcolour"]) { schedule["form"].push({"field":"#rowcontextcardcolour","value":b["CardColour"]}); } if(b["Class"]) { classes=b["Class"].split(" "); $.each(classes,function(a,b) { type=b.split("-"); if(type[0]=="mb") { type="bottom"; } if(type[0]=="mt") { type="top"; } if(type[0]=="ms") { type="start"; } if(type[0]=="me") { type="end"; } if(b && b!=buildfields["row"]["rowcontextmargin"+type]) { schedule["form"].push({"field":"#rowcontextmargin"+type,"value":b}); } }); } if(b["ContainerClass"]) { classes=b["ContainerClass"].split(" "); $.each(classes,function(a,b) { type=b.split("-"); if(type[0]=="pb") { type="bottom"; } if(type[0]=="pt") { type="top"; } if(type[0]=="ps") { type="start"; } if(type[0]=="pe") { type="end"; } if(b && b!=buildfields["row"]["rowcontextpadding"+type]) { schedule["form"].push({"field":"#rowcontextpadding"+type,"value":b}); } }); } if(b["Gutter-X"] && b["Gutter-X"]!=buildfields["row"]["rowcontextgutterx"]) { schedule["form"].push({"field":"#rowcontextgutterx","value":b["Gutter-X"]}); } if(b["Gutter-Y"] && b["Gutter-Y"]!=buildfields["row"]["rowcontextguttery"]) { schedule["form"].push({"field":"#rowcontextguttery","value":b["Gutter-Y"]}); } $.each(b["RowColumns"],function(a,b) { schedule["form"].push({"add":"column","id":b.SystemID,"to":rowid}); colid=b.SystemID if(b["CustomID"] && b["CustomID"]!=buildfields["column"]["columncontextid"]) { schedule["form"].push({"field":"#columncontextid","value":b["CustomID"]}); } if(b["CustomClass"] && b["CustomClass"]!=buildfields["column"]["columncontextclass"]) { schedule["form"].push({"field":"#columncontextclass","value":b["CustomClass"]}); } if(b["Title"] && b["Title"]!=buildfields["column"]["columncontexttitle"]) { schedule["form"].push({"field":"#columncontexttitle","value":b["Title"]}); } if(b["Description"] && b["Description"]!=buildfields["column"]["columncontextdescription"]) { schedule["form"].push({"field":"#columncontextdescription","value":b["Description"]}); } if(b["DescriptionHTML"] && b["DescriptionHTML"]!=buildfields["column"]["columncontextdescriptionhtml"]) { schedule["form"].push({"field":"#columncontextdescriptionhtml","value":b["DescriptionHTML"]}); } if(b["Visible"] && b["Visible"]!=buildfields["column"]["columncontextvisible"]) { schedule["form"].push({"field":"#columncontextvisible","value":b["Visible"]}); } if(b["Card"] && b["Card"]!=buildfields["column"]["columncontextcard"]) { schedule["form"].push({"field":"#columncontextcard","value":b["Card"]}); } if(b["CardColour"] && b["CardColour"]!=buildfields["column"]["columncontextcardcolour"]) { schedule["form"].push({"field":"#columncontextcardcolour","value":b["CardColour"]}); } if(b["ContainerClass"]) { classes=b["ContainerClass"].split(" "); $.each(classes,function(a,b) { type=b.split("-"); if(type[0]=="pb") { type="bottom"; } if(type[0]=="pt") { type="top"; } if(type[0]=="ps") { type="start"; } if(type[0]=="pe") { type="end"; } if(b && b!=buildfields["column"]["columncontextpadding"+type]) { schedule["form"].push({"field":"#columncontextpadding"+type,"value":b}); } }); } if(b["Class"]) { classes=b["Class"].split(" "); $.each(classes,function(a,b) { type=b.split("-"); if(type.length<3) { if(b && b!=buildfields["column"]["columncontextcontextwidthxs"]) { schedule["form"].push({"field":"#columncontextcontextwidthxs","value":b}); } } if(type.length==3) { if(b && b!=buildfields["column"]["columncontextcontextwidth"+type[1]]) { schedule["form"].push({"field":"#columncontextcontextwidth"+type[1],"value":b}); } } }); } $.each(b["Fields"],function(a,b) { schedule["form"].push({"add":"field","id":b.SystemID,"to":colid}); f=fields[b.SystemID]; fi=b.SystemID; if(f["Type"] && f["Type"]!=buildfields["field"]["fieldcontexttype"]) { schedule["form"].push({"field":"#fieldcontexttype","value":f["Type"],"delay":2,"id":fi,"options":f.Options}); } if(f["Attributes"]["name"] && f["Attributes"]["name"]!=buildfields["field"]["fieldcontextname"]) { schedule["form"].push({"field":"#fieldcontextname","value":f["Attributes"]["name"]}); } if(f["Attributes"]["customid"] && f["Attributes"]["customid"]!=buildfields["field"]["fieldcontextid"]) { schedule["form"].push({"field":"#fieldcontextid","value":f["Attributes"]["customid"]}); } if(f["Attributes"]["customclass"] && f["Attributes"]["customclass"]!=buildfields["field"]["fieldcontextclass"]) { schedule["form"].push({"field":"#fieldcontextclass","value":f["Attributes"]["customclass"]}); } if( f["Label"]!=buildfields["field"]["fieldcontextlabel"]) { schedule["form"].push({"field":"#fieldcontextlabel","value":f["Label"]}); } if(f["Note"] && f["Note"]!=buildfields["field"]["fieldcontextnote"]) { schedule["form"].push({"field":"#fieldcontextnote","value":f["Note"]}); } if(f["NotePosition"] && f["NotePosition"]!=buildfields["field"]["fieldcontextnoteposition"]) { schedule["form"].push({"field":"#fieldcontextnoteposition","value":f["NotePosition"]}); } if(f["Attributes"]["placeholder"] && f["Attributes"]["placeholder"]!=buildfields["field"]["fieldcontextplaceholder"]) { schedule["form"].push({"field":"#fieldcontextplaceholder","value":f["Attributes"]["placeholder"]}); } if(f["Attributes"]["defaultvalue"] && f["Attributes"]["defaultvalue"]!=buildfields["field"]["fieldcontextdefault"]) { schedule["form"].push({"field":"#fieldcontextdefault","value":f["Attributes"]["defaultvalue"]}); } if(f["Attributes"]["autocomplete"] && f["Attributes"]["autcomplete"]!=buildfields["field"]["fieldcontextautcomplete"]) { schedule["form"].push({"field":"#fieldcontextautocomplete","value":f["Attributes"]["autocomplete"]}); } if(f["Attributes"]["autoheight"] && f["Attributes"]["autoheight"]!=buildfields["field"]["fieldcontextautoheight"]) { schedule["form"].push({"field":"#fieldcontextautoheight","value":f["Attributes"]["autoheight"]}); } if(f["Attributes"]["html"] && f["Attributes"]["html"]!=buildfields["field"]["fieldcontexthtml"]) { schedule["form"].push({"field":"#fieldcontexthtml","value":f["Attributes"]["html"]}); } if(f["Attributes"]["disabled"] && f["Attributes"]["disabled"]!=buildfields["field"]["fieldcontextdisabled"]) { schedule["form"].push({"field":"#fieldcontextdisabled","value":f["Attributes"]["disabled"]}); } if(f["Attributes"]["donotdisable"] && f["Attributes"]["donotdisable"]!=buildfields["field"]["fieldcontextenabled"]) { schedule["form"].push({"field":"#fieldcontextenabled","value":f["Attributes"]["donotdisable"]}); } if(f["Attributes"]["floatinglabel"] && f["Attributes"]["floatinglabel"]!=buildfields["field"]["fieldcontextfloatinglabel"]) { schedule["form"].push({"field":"#fieldcontextfloatinglabel","value":f["Attributes"]["floatinglabel"]}); } if(f["Attributes"]["visible"] && f["Attributes"]["visible"]!=buildfields["field"]["fieldcontextvisible"]) { schedule["form"].push({"field":"#fieldcontextvisible","value":f["Attributes"]["visible"]}); } if(f["Attributes"]["readonly"] && f["Attributes"]["readonly"]!=buildfields["field"]["fieldcontextreadonly"]) { schedule["form"].push({"field":"#fieldcontextreadonly","value":f["Attributes"]["readonly"]}); } if(f["Attributes"]["required"] && f["Attributes"]["required"]!=buildfields["field"]["fieldcontextrequired"]) { schedule["form"].push({"field":"#fieldcontextrequired","value":f["Attributes"]["required"]}); } if(f["Attributes"]["height"] && f["Attributes"]["height"]!=buildfields["field"]["fieldcontexttextareaheight"]) { schedule["form"].push({"field":"#fieldcontexttextareaheight","value":f["Attributes"]["height"]}); } if(f["Attributes"]["min"] && f["Attributes"]["min"]!=buildfields["field"]["fieldcontextmin"]) { schedule["form"].push({"field":"#fieldcontextmin","value":f["Attributes"]["min"]}); } if(f["Attributes"]["max"] && f["Attributes"]["max"]!=buildfields["field"]["fieldcontextmax"]) { schedule["form"].push({"field":"#fieldcontextmax","value":f["Attributes"]["max"]}); } if(f["Attributes"]["step"] && f["Attributes"]["step"]!=buildfields["field"]["fieldcontextstep"]) { schedule["form"].push({"field":"#fieldcontextstep","value":f["Attributes"]["step"]}); } if(f["Attributes"]["minlength"] && f["Attributes"]["minlength"]!=buildfields["field"]["fieldcontextminlength"]) { schedule["form"].push({"field":"#fieldcontextminlength","value":f["Attributes"]["minlength"]}); } if(f["Attributes"]["maxlength"] && f["Attributes"]["maxlength"]!=buildfields["field"]["fieldcontextmaxlength"]) { schedule["form"].push({"field":"#fieldcontextmaxlength","value":f["Attributes"]["maxlength"]}); } if(f["CustomValidation"]["Required"] && f["CustomValidation"]["Required"]!=buildfields["field"]["fieldcontextrequiredalert"]) { schedule["form"].push({"field":"#fieldcontextrequiredalert","value":f["CustomValidation"]["Required"]}); } if(f["CustomValidation"]["RangeUnder"] && f["CustomValidation"]["RangeUnder"]!=buildfields["field"]["fieldcontextrangeunderalert"]) { schedule["form"].push({"field":"#fieldcontextrangeunderalert","value":f["CustomValidation"]["RangeUnder"]}); } if(f["CustomValidation"]["RangeOver"] && f["CustomValidation"]["RangeOver"]!=buildfields["field"]["fieldcontextrangeoveralert"]) { schedule["form"].push({"field":"#fieldcontextrangeoveralert","value":f["CustomValidation"]["RangeOver"]}); } if(f["CustomValidation"]["StepMismtach"] && f["CustomValidation"]["StepMismatch"]!=buildfields["field"]["fieldcontextstepmismatchalert"]) { schedule["form"].push({"field":"#fieldcontextstepmismatchalert","value":f["CustomValidation"]["StepMismatch"]}); } if(f["CustomValidation"]["TooShort"] && f["CustomValidation"]["TooShort"]!=buildfields["field"]["fieldcontexttooshortalert"]) { schedule["form"].push({"field":"#fieldcontexttooshortalert","value":f["CustomValidation"]["TooShort"]}); } if(f["CustomValidation"]["TooLong"] && f["CustomValidation"]["TooLong"]!=buildfields["field"]["fieldcontexttoolongalert"]) { schedule["form"].push({"field":"#fieldcontexttoolongalert","value":f["CustomValidation"]["TooLong"]}); } if(f["CustomValidation"]["CustomEvent"] && f["CustomValidation"]["CustomEvent"]!=buildfields["field"]["fieldcontexteventcustomalert"]) { schedule["form"].push({"field":"#fieldcontexteventcustomalert","value":f["CustomValidation"]["CustomEvent"]}); } if(f["Attributes"]["class"]) { classes=f["Attributes"]["class"].split(" "); $.each(classes,function(a,b) { type=b.split("-"); if(type[0]=="mb") { type="bottom"; } if(type[0]=="mt") { type="top"; } if(type[0]=="ms") { type="start"; } if(type[0]=="me") { type="end"; } if(b && b!=buildfields["row"]["fieldcontextmargin"+type]) { schedule["form"].push({"field":"#fieldcontextmargin"+type,"value":b}); } }); } }); }); }); }); }); runschedule(schedule); } ); } var p=1; function runschedule(sched) { p=1; $.each(sched,function(a,b) { $.each(b,function(c,d) { if(d.add=="form") { setTimeout(function() { formsettings(); $("#metadata").get(0).reset(); },250*p); p++; } if(d.add=="section") { setTimeout(function() { addpage(d["id"].replaceAll("section","")); $("#metadata").get(0).reset();},p*250); p++; } if(d.add=="sectioncolumn") { setTimeout(function() { addpagecolumn(document.getElementById(d["to"]),d["id"].replaceAll("sectioncol",""));$("#metadata").get(0).reset(); },p*250); p++; } if(d.add=="row") { setTimeout(function() { addrow(document.getElementById(d.to),d["id"].replaceAll("formrow",""));$("#metadata").get(0).reset(); },p*250); p++; } if(d.add=="column") { setTimeout(function() { addcolumn(document.getElementById(d.to),d["id"].replaceAll("formcol","")); $("#metadata").get(0).reset();},p*250); p++; } if(d.add=="field") { setTimeout(function() { addfield(document.getElementById(d.to),d["id"].replaceAll("field","")); $("#metadata").get(0).reset();},p*250); p++; } if(d.field) { update(d.field,d.value); if(d.field=="#sectioncontextpage") { p=p+2; setTimeout(function() { getcontext(document.getElementById(d.id)); },p*250); } if(d.field=="#fieldcontexttype") { if(d.value=="select" || d.value=="radio" || d.value=="checkbox") { p++; setTimeout(function() { optionsupdate("#"+d.id,d["options"]); },250*p); p++; } } if(d.delay) { p=p+d.delay; } else { p++; } } }); }); setTimeout(function() { gotopage(1) },p*250); p=p+2; setTimeout(function() { preview() }, p*250); } function buildform(id) { formmapping={}; sectionmapping={}; formmapping["ID"]="formcontextid"; formmapping["Name"]="formcontextname"; formmapping["SaveToLocal"]="formcontextsave"; formmapping["SaveOpt"]="formcontextsaveopt"; formmapping["Colour"]="formcontextpagecolour"; formmapping["TextColour"]="formcontexttextcolour"; formmapping["Class"]="formcontextcontainercontextwidth"; formmapping["Heading|logo|src"]="formcontextlogo"; formmapping["Heading|logo|alt"]="formcontextlogoalt"; formmapping["Heading[logo|containerclasses"]="formcontextlogocontextwidth"; formmapping["Heading|text|containerclasses"]="formcontexttextcontextwidth"; formmapping["Heading|text|title|text"]="formcontexttitle"; formmapping["Heading|text|title|classes"]="formcontexttitlecontextalign"; formmapping["Heading|text|description|text"]="formcontextdescription"; formmapping["Heading|text|description|classes"]="formcontextdescriptioncontextalign"; formmapping["Heading|text|description|renderHTML"]="formcontextdescriptionhtml"; formmapping["Pagination|Position"]="formcontextpaginationposition"; formmapping["Pagination|Format"]="formcontextpagination"; formmapping["Pagination|Submit"]="formcontextpaginationsubmit"; formmapping["Pagination|Scroll"]="formpaginationscroll"; sectionmapping["CustomID"]="sectioncontextid"; sectionmapping["CustomClass"]="sectioncontextclass"; sectionmapping["Title"]="sectioncontexttitle"; sectionmapping["Description"]="sectioncontextdescription"; sectionmapping["DescriptionHTML"]="sectioncontextdescriptionhtml"; sectionmapping["Gutter-X"]="sectioncontextgutterx"; sectionmapping["Gutter-Y"]="sectioncontextguttery"; sectionmapping["Class"]="sectioncontextmargin"; sectionmapping["ContainerClas"]="sectioncontextpadding"; sectionmapping["Visible"]="sectioncontextvisible"; sectionmapping["Card"]="sectioncontextcard"; sectionmapping["CardColour"]="sectioncontextcardcolour"; sectionmapping["NoPDF"]="sectioncontextdescriptionhtml"; $.ajax({ method:"POST", url:"/scripts/getbuildjson.php", data:{id:id}, dataType:"json" }).done(function(msg) { offcanvasList[0].show(); $("#formcontext").show(); $("#metadata").get(0).reset(); if(msg.response=="OK") { json=JSON.parse(msg.json); $("#section0").remove(); fields=json["fields"]; $.each(json["layout"]["Form"],function(a,b) { if(typeof b=="object") { if(a=="Heading") { if(b["logo"]["src"]) { update("#"+formmapping["Heading|logo|src"],b["logo"]["src"]); } if(b["logo"]["alt"]) { update("#"+formmapping["Heading|logo|alt"],b["logo"]["alt"]); } if(b["logo"]["containerclasses"]) { classupdate("#"+formmapping["Heading[logo|containerclasses"],b["logo"]["containerclasses"]); } if(b["text"]["containerclasses"]) { classupdate("#"+formmapping["Heading|text|containerclasses"],b["text"]["containerclasses"]); } if(b["text"]["title"]["text"]) { update("#"+formmapping["Heading|text|title|text"],b["text"]["title"]["text"]); } if(b["text"]["title"]["classes"]) { alignupdate("#"+formmapping["Heading|text|title|classes"],b["text"]["title"]["classes"]); } if(b["text"]["description"]["text"]) { update("#"+formmapping["Heading|text|description|text"],b["text"]["description"]["text"]); } if(b["text"]["description"]["classes"]) { alignupdate("#"+formmapping["Heading|text|description|classes"],b["text"]["description"]["classes"]); } } if(a=="Pagination") { $.each(b,function(c,d) { if(typeof d!="undefined") { update("#"+formmapping[a+"|"+c],d); } }); } } else { if(a=="Class" && typeof b!="undefined") { classupdate("#"+formmapping[a],b); } else { if(typeof b!="undefined") { update("#"+formmapping[a],b); } } } }); $.each(json["layout"]["Form"]["Sections"],function(secid,secdetail) { setTimeout(function() { addpage(secdetail["SystemID"].replaceAll("section","")); $("#metadata").get(0).reset();},p*250); p++; update("#sectioncontextpage",secdetail["Page"]); p=p+2; setTimeout(function() { getcontext(document.getElementById(secdetail["SystemID"])); $("#metadata").get(0).reset();},p*250); p=p+2; $.each(secdetail,function(a,b) { if(a=="Class" && typeof b!="undefined") { marginsupdate("#"+sectionmapping[a],b); } else { if(a=="ContainerClass"&& typeof b!="undefined") { paddingupdate("#"+sectionmapping[a],b); } else { if(typeof b!="undefined") { update("#"+sectionmapping[a],b); } } } }); $.each(secdetail["SectionColumns"],function(seccolid,seccoldetail) { setTimeout(function() { addpagecolumn(document.getElementById(secdetail["SystemID"]),seccoldetail["SystemID"].replaceAll("sectioncol","")); $("#metadata").get(0).reset();},p*250); p++; update("#sectioncolumncontextid",seccoldetail["CustomID"],); update("#sectioncolumncontextclass",seccoldetail["CustomClass"]); update("#sectioncolumncontexttitle",seccoldetail["Title"]); update("#sectioncolumncontextdescription",seccoldetail["Description"]); update("#sectioncolumncontextdescriptionhtml",seccoldetail["DescriptionHTML"]); update("#sectioncolumncontextvisible",seccoldetail["Visible"]); update("#sectioncolumncontextreplicable",seccoldetail["Replicable"]); update("#sectioncolumncontextreplicableadd",seccoldetail["ReplicableAdd"]); update("#sectioncolumncontextreplicabledelete",seccoldetail["ReplicableDelete"]); update("#sectioncolumncontextcard",((seccoldetail["Card"]==true) ? "Yes" : "No")); update("#sectioncolumncontextcardcolour",seccoldetail["CardColour"]); paddingupdate("#sectioncolumncontextpadding",seccoldetail["ContainerClass"]); classupdate("#sectioncolumncontextcontextwidth",seccoldetail["Class"]); $.each(seccoldetail["Rows"],function(rowid,rowdetail) { setTimeout(function() { addrow(document.getElementById(seccoldetail["SystemID"]),rowdetail["SystemID"].replaceAll("formrow","")); $("#metadata").get(0).reset();},p*250); p++; update("#rowcontextid",rowdetail["CustomID"]); update("#rowcontextclass",rowdetail["CustomClass"]); update("#rowcontexttitle",rowdetail["Title"]); update("#rowcontextdescription",rowdetail["Description"]); update("#rowcontextdescriptionhtml",rowdetail["DescriptionHTML"]); update("#rowcontextvisible",rowdetail["Visible"]); update("#rowcontextreplicable",rowdetail["Replicable"]); update("#rowcontextreplicableadd",rowdetail["ReplicableAdd"]); update("#rowcontextreplicabledelete",rowdetail["ReplicableDelete"]); update("#rowcontextcard",((rowdetail["Card"]==true) ? "Yes" : "No")); update("#rowcontextcardcolour",rowdetail["CardColour"]); marginsupdate("#rowcontextmargin",rowdetail["Class"]); paddingupdate("#rowcontextpadding",rowdetail["ContainerClass"]); update("#rowcontextgutterx",((rowdetail["Gutter-X"]) ? rowdetail["Gutter-X"] : 0)); update("#rowcontextguttery",((rowdetail["Gutter-Y"]) ? rowdetail["Gutter-Y"] : 0)); $.each(rowdetail["RowColumns"],function(colid,coldetail) { setTimeout(function() { addcolumn(document.getElementById(rowdetail["SystemID"]),coldetail["SystemID"].replaceAll("formcol","")); $("#metadata").get(0).reset();},p*250); p++; update("#columncontextid",coldetail["CustomID"]); update("#columncontextclass",coldetail["CustomClass"]); update("#columncontexttitle",coldetail["Title"]); update("#columncontextdescription",coldetail["Description"]); update("#columncontextdescriptionhtml",coldetail["DescriptionHTML"]); update("#columncontextvisible",coldetail["Visible"]); update("#columncontextcard",((coldetail["Card"]==true) ? "Yes" : "No")); update("#columncontextcardcolour",coldetail["CardColour"]); paddingupdate("#columncontextpadding",coldetail["ContainerClass"]); classupdate("#columncontextcontextwidth",coldetail["Class"]); $.each(coldetail["Fields"],function(fieldid,fielddetail) { setTimeout(function() { $("#metadata").get(0).reset(); $("#fieldcontextoptions").html(""); addfield(document.getElementById(coldetail["SystemID"]),fielddetail["SystemID"].replaceAll("field","")); },p*250); p++; update("#fieldcontexttype",fields[fielddetail["SystemID"]]["Type"]); update("#fieldcontextsize",fields[fielddetail["SystemID"]]["Attributes"]["inputsize"]); update("#fieldcontextname",fields[fielddetail["SystemID"]]["Attributes"]["name"]); update("#fieldcontextid",fields[fielddetail["SystemID"]]["Attributes"]["customid"]); update("#fieldcontextclass",fields[fielddetail["SystemID"]]["Attributes"]["customclass"]); update("#fieldcontextlabel",fields[fielddetail["SystemID"]]["Label"]); update("#fieldcontextnote",fields[fielddetail["SystemID"]]["Note"]); update("#fieldcontextnoteshow",fields[fielddetail["SystemID"]]["NotePosition"]); update("#fieldcontextplaceholder",fields[fielddetail["SystemID"]]["Attributes"]["placeholder"]); update("#fieldcontextdefault",fields[fielddetail["SystemID"]]["Attributes"]["defaultvalue"]); update("#fieldcontextautocomplete",fields[fielddetail["SystemID"]]["Attributes"]["autocomplete"]); update("#fieldcontextmin",fields[fielddetail["SystemID"]]["Attributes"]["min"]); update("#fieldcontextmax",fields[fielddetail["SystemID"]]["Attributes"]["max"]); update("#fieldcontextstep",fields[fielddetail["SystemID"]]["Attributes"]["step"]); update("#fieldcontextminlength",fields[fielddetail["SystemID"]]["Attributes"]["minlength"]); update("#fieldcontextmaxlength",fields[fielddetail["SystemID"]]["Attributes"]["maxlength"]); update("#fieldcontextpattern",fields[fielddetail["SystemID"]]["Attributes"]["pattern"]); boolupdate("#fieldcontextautoheight",fields[fielddetail["SystemID"]]["Attributes"]["autoheight"]); boolupdate("#fieldcontextdisabled",fields[fielddetail["SystemID"]]["Attributes"]["disabled"]); boolupdate("#fieldcontextenabled",fields[fielddetail["SystemID"]]["Attributes"]["donotdisable"]); boolupdate("#fieldcontextcheckcols",fields[fielddetail["SystemID"]]["Attributes"]["twocols"]); boolupdate("#fieldcontextotherspecify",fields[fielddetail["SystemID"]]["Attributes"]["otherspecify"]); boolupdate("#fieldcontextfloatinglabel",fields[fielddetail["SystemID"]]["Attributes"]["floatinglabel"]); boolupdate("#fieldcontextvisible",fields[fielddetail["SystemID"]]["Attributes"]["visible"]); boolupdate("#fieldcontextreadonly",fields[fielddetail["SystemID"]]["Attributes"]["readonly"]); boolupdate("#fieldcontextrequired",fields[fielddetail["SystemID"]]["Attributes"]["required"]); optionsupdate("#"+fielddetail["SystemID"],fields[fielddetail["SystemID"]]["Options"]); update("#fieldcontexttextareaheight",fields[fielddetail["SystemID"]]["Attributes"]["height"]) update("#fieldcontextrequiredalert",fields[fielddetail["SystemID"]]["CustomValidation"]["Required"]); update("#fieldcontextpatternalert",fields[fielddetail["SystemID"]]["CustomValidation"]["Pattern"]); update("#fieldcontexttooshortdalert",fields[fielddetail["SystemID"]]["CustomValidation"]["TooShort"]); update("#fieldcontexttoolongalert",fields[fielddetail["SystemID"]]["CustomValidation"]["TooLong"]); update("#fieldcontexttoorangerunderalert",fields[fielddetail["SystemID"]]["CustomValidation"]["RangeUnder"]); update("#fieldcontexttoorangeroveralert",fields[fielddetail["SystemID"]]["CustomValidation"]["RangeOver"]); update("#fieldcontextstepmismatchalert",fields[fielddetail["SystemID"]]["CustomValidation"]["StepMismatch"]); update("#fieldcontextmismatchalert",fields[fielddetail["SystemID"]]["CustomValidation"]["TypeMismatch"]); update("#fieldcontexteventcustomalert",fields[fielddetail["SystemID"]]["CustomValidation"]["CustomEvent"]); marginsupdate("#fieldcontextmargin",fields[fielddetail["SystemID"]]["Attributes"]["class"]); }); }); }); }); }); // Pagination at the end when pages have been added update("#formcontextdescription",json["layout"]["Form"]["Heading"]["text"]["description"]["text"]); }; }); } function optionsupdate(e,options) { if($(options).length>0) { extra = `  ` $("#fieldcontextoptions").html(""); i=0; $.each(options,function(a,b) { $("#fieldcontextoptions").append(`` + extra + ``); i++; }); setoptions(e); } } function boolupdate(id,value) { if(typeof value=="undefined" || (value=="true" && $(id).is(":checked")) || (value=="false" && $(id).is(":checked")==false)) { setTimeout(function() { $(id).trigger("change"); return false; },250*p); } else { setTimeout(function() { $(id).addClass("fa-beat"); $(id).css("--fa-animation-duration","0.25s"); $(id).css("background-color","lightGreen"); },(250*p)-200); setTimeout(function() { if(value=="true") { $(id).prop("checked",true); } else { $(id).prop("checked",false); } $(id).trigger("change"); $(id).removeClass("fa-beat"); $(id).css("--fa-animation-duration","0.25s"); $(id).css("background-color",""); },250*p); p++; } } function sleep (time) { return new Promise((resolve) => setTimeout(resolve, time)); } function update(id,value,defaultvalue) { if(typeof defaultvalue=="undefined") { defaultvalue=""; } setTimeout(function() { $(id).addClass("fa-beat"); $(id).css("--fa-animation-duration","0.25s"); $(id).css("background-color","lightGreen"); },(250*p)-225); setTimeout(function() { $(id).focus(); if($(id).attr("type")=="checkbox") { if(value=="true") { $(id).prop("checked",true); } else { $(id).prop("checked",false); } } else { $(id).val(value); } $(id).trigger("change"); $(id).removeClass("fa-beat"); $(id).css("background-color",""); },250*p); } function classupdate(id,classes,defaultvalue) { classlist={}; classlist["xxl"]="col-xxl"; classlist["xl"]="col-xl"; classlist["lg"]="col-lg"; classlist["md"]="col-md"; classlist["sm"]="col-sm"; classlist["xs"]="col-"; var val={}; if(typeof classes=="undefined" || classes==defaultvalue) { return false; } classes=classes.split(" "); $.each(classlist,function(a,b) { $.each(classes,function(c,d) { if(d.indexOf(b)>=0) { val[a]=d; classes[c]=""; return false; } else { if(d=="col") { val["xs"]="col"; classes[c]=""; return false; } } }); if(typeof val[a]=="undefined") { val[a]=""; } }); newval={}; newval["xs"]=val["xs"]; newval["sm"]=val["sm"]; newval["md"]=val["md"]; newval["lg"]=val["lg"]; newval["xl"]=val["xl"]; newval["xxl"]=val["xxl"]; $.each(newval,function(a,b) { update(id+a,b); }) } function alignupdate(id,classes,defaultvalue) { classlist={}; classlist["xxl"]="text-xxl"; classlist["xl"]="text-xl"; classlist["lg"]="text-lg"; classlist["md"]="text-md"; classlist["sm"]="text-sm"; classlist["xs"]="text-"; var val={}; if(typeof classes=="undefined" || classes==defaultvalue) { return false; } classes=classes.split(" "); $.each(classlist,function(a,b) { $.each(classes,function(c,d) { if(d.indexOf(b)>=0) { val[a]=d; classes[c]=""; return false; } else { if(d=="col") { val["xs"]="col"; classes[c]=""; return false; } } }); if(typeof val[a]=="undefined") { val[a]=""; } }); newval={}; newval["xs"]=val["xs"]; newval["sm"]=val["sm"]; newval["md"]=val["md"]; newval["lg"]=val["lg"]; newval["xl"]=val["xl"]; newval["xxl"]=val["xxl"]; $.each(newval,function(a,b) { update(id+a,b); }); } function marginsupdate(id,classes,defaultvalue) { classlist={}; classlist["top"]="mt-" classlist["end"]="me-"; classlist["bottom"]="mb-"; classlist["start"]="ms-"; if(typeof classes=="undefined" || defaultvalue==classes) { return false; } var val={}; classes=classes.split(" "); $.each(classlist,function(a,b) { $.each(classes,function(c,d) { if(d.indexOf(b)>=0) { val[a]=d; classes[c]=""; return false; } }); if(typeof val[a]=="undefined") { val[a]=b+"0"; } }); $.each(val,function(a,b) { update(id+a,b); }) } function paddingupdate(id,classes,defaultvalue) { classlist={}; classlist["top"]="pt-" classlist["end"]="pe-"; classlist["bottom"]="pb-"; classlist["start"]="ps-"; var val={}; if(typeof classes=="undefined" || classes==defaultvalue) { return false; } classes=classes.split(" "); $.each(classlist,function(a,b) { $.each(classes,function(c,d) { if(d.indexOf(b)>=0) { val[a]=d; classes[c]=""; return false; } }); if(typeof val[a]=="undefined") { val[a]=b+"0"; } }); $.each(val,function(a,b) { update(id+a,b); }) } function icons(ele) { $("#icons").parent().addClass("d-none"); if(typeof icondelay!="undefined") { clearTimeout(icondelay); } icondelay=setTimeout(function() { if(ele.value.trim()!="" ) { $.ajax({ method:"POST", url:"/findicons.php", data:{search:ele.value,format:"html",nonce:document.getElementById("inonce").value}, }).done(function(msg) { if(msg.trim()) { $("#icons").html(msg); $("#icons").parent().removeClass("d-none"); toolovers(); $("#icons").find("i").on("click",function() { ele.value=$(this).data("value"); $(ele).trigger("change"); $("#icons").parent().addClass("d-none"); }); } else { $("#icons").parent().addClass("d-none"); } }) } else { $("#icons").parent().addClass("d-none"); } },500); }