From ce858e63ed62a163adacc5e1d26ab858ad249065 Mon Sep 17 00:00:00 2001 From: Kevin Chappell Date: Wed, 17 Aug 2016 15:07:03 +0100 Subject: [PATCH] Bugfix: Cannot render multiple (#223) --- demo/assets/js/form-render.min.js | 2 +- demo/assets/js/form-render.min.js.map | 2 +- dist/form-render.js | 15 +++++++-------- dist/form-render.min.js | 2 +- src/js/form-render.js | 5 ++--- 5 files changed, 12 insertions(+), 14 deletions(-) diff --git a/demo/assets/js/form-render.min.js b/demo/assets/js/form-render.min.js index 139ef0ea1..ad2d8e02b 100644 --- a/demo/assets/js/form-render.min.js +++ b/demo/assets/js/form-render.min.js @@ -3,4 +3,4 @@ formBuilder - https://formbuilder.online/ Version: 1.15.2 Author: Kevin Chappell */ -"use strict";function FormRenderFn(e,t){var n=this,r={destroyTemplate:!0,container:!1,dataType:"xml",formData:!1,label:{formRendered:"Form Rendered",noFormData:"No form data.",other:"Other",selectColor:"Select Color"},render:!0,notify:{error:function(e){return console.error(e)},success:function(e){return console.log(e)},warning:function(e){return console.warn(e)}}},a={},o=$.extend(!0,r,e);a.getElement=function(){return t.id||(t.id=a.makeId(t)),document.getElementById(t.id)},a.makeId=function(e){var t=(new Date).getTime();return e.tagName+"-"+t},!o.formData&&t&&(t=a.getElement(),o.formData=t.value),a.markup=function(e){var t=arguments.length<=1||void 0===arguments[1]?"":arguments[1],n=arguments.length<=2||void 0===arguments[2]?{}:arguments[2],r=void 0,o=document.createElement(e),i=function(e){return Array.isArray(e)?"array":"undefined"==typeof e?"undefined":_typeof(e)},l={string:function(e){o.innerHTML=e},object:function(e){return o.appendChild(e)},array:function(e){for(var t=0;t*'),"hidden"!==i.type&&(s&&(s='?'),n='");var u=i.label;delete i.label,delete i.description;var f=a.attrString(i);switch(i.type){case"textarea":case"rich-text":delete i.type,t=n+"";break;case"select":i.type=i.type.replace("-group",""),d.length&&d.each(function(e,t){e=e;var n=a.parseAttrs(t.attributes),o=a.attrString(n);r+=""}),t=n+"";break;case"checkbox-group":case"radio-group":var p=!1;i.type=i.type.replace("-group",""),i.other&&(delete i.other,p=!0),d.length&&!function(){var e="checkbox"===i.type?i.name+"[]":i.name,t=void 0;if(d.each(function(n,o){var l=$.extend({},i,a.parseAttrs(o.attributes));l.selected&&(delete l.selected,l.checked=null),l.name=e,l.id=i.id+"-"+n,t=a.attrString(l),r+="
"}),p){var n={id:i.id+"-other",name:e,"class":i["class"]+" other-option"};t=a.attrString($.extend({},i,n)),r+=" '}}(),t=n+'
'+r+"
";break;case"text":case"password":case"email":case"number":case"file":case"hidden":case"date":case"autocomplete":t=n+" ";break;case"color":t=n+" "+o.label.selectColor;break;case"button":case"submit":t="";break;case"checkbox":t=" "+n,i.toggle&&setTimeout(function(){$(document.getElementById(i.id)).kcToggle()},100);break;default:t="<"+i.type+" "+f+">"+u+""}if("hidden"!==i.type){var m=i.id?"form-group field-"+i.id:"";t=a.markup("div",t,{className:m})}else t=a.markup("input",null,i);return t},a.hyphenCase=function(e){return e=e.replace(/[^\w\s\-]/gi,""),e=e.replace(/([A-Z])/g,function(e){return"-"+e.toLowerCase()}),e.replace(/\s/g,"-").replace(/^-+/g,"")},a.attrString=function(e){var t=[];for(var n in e)e.hasOwnProperty(n)&&(n=a.safeAttr(n,e[n]),t.push(n.name+n.value));return t.join(" ")},a.safeAttr=function(e,t){var n={className:"class"};return e=n[e]||e,t=t?window.JSON.stringify(t):!1,t=t?"="+t:"",{name:e,value:t}},a.safeAttrName=function(e){var t={className:"class"};return t[e]||a.hyphenCase(e)},a.parseAttrs=function(e){var t={};for(var n in e)e.hasOwnProperty(n)&&(t[e[n].name]=e[n].value);return t},Element.prototype.appendFormFields=function(e){var t=this;e.reverse();for(var n=e.length-1;n>=0;n--)t.appendChild(e[n])},Element.prototype.emptyContainer=function(){for(var e=this;e.lastChild;)e.removeChild(e.lastChild)};var i=function(){for(var e=document.getElementsByClassName("other-option"),t=function(){var t=document.getElementById(e[n].id+"-value");e[n].onclick=function(e){var n=this;this.checked?(t.style.display="inline-block",n.nextElementSibling.style.display="none",t.oninput=function(e){n.value=this.value}):(t.style.display="none",n.nextElementSibling.style.display="inline-block",t.oninput=void 0)}},n=0;n').insertAfter(t).append(t);o.toggleClass("on",t.is(":checked"));var i='
'+a.labels.on+"
",l='
'+a.labels.off+"
",s='
',c='
'+i+s+l+"
";o.append(c),o.click(function(){t.attr("checked",!t.attr("checked")),e(this).toggleClass("on")})};e.fn.kcToggle=function(n){var r=this;return r.each(function(){var r=e(this);if(!r.data("kcToggle")){var a=new t(r,n);r.data("kcToggle",a)}})}}(jQuery);var _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol?"symbol":typeof e};!function(e){e.fn.formRender=function(e){this.each(function(){var t=new FormRenderFn(e,this);return t})}}(jQuery); \ No newline at end of file +"use strict";function FormRenderFn(e,t){var n=this,r={destroyTemplate:!0,container:!1,dataType:"xml",formData:!1,label:{formRendered:"Form Rendered",noFormData:"No form data.",other:"Other",selectColor:"Select Color"},render:!0,notify:{error:function(e){return console.error(e)},success:function(e){return console.log(e)},warning:function(e){return console.warn(e)}}},a={},o=$.extend(!0,r,e);a.getElement=function(){return t.id||(t.id=a.makeId(t)),document.getElementById(t.id)},a.makeId=function(e){var t=(new Date).getTime();return e.tagName+"-"+t},!o.formData&&t&&(t=a.getElement(),o.formData=t.value),a.markup=function(e){var t=arguments.length<=1||void 0===arguments[1]?"":arguments[1],n=arguments.length<=2||void 0===arguments[2]?{}:arguments[2],r=void 0,o=document.createElement(e),i=function(e){return Array.isArray(e)?"array":"undefined"==typeof e?"undefined":_typeof(e)},l={string:function(e){o.innerHTML=e},object:function(e){return o.appendChild(e)},array:function(e){for(var t=0;t*'),"hidden"!==i.type&&(s&&(s='?'),n='");var u=i.label;delete i.label,delete i.description;var p=a.attrString(i);switch(i.type){case"textarea":case"rich-text":delete i.type,t=n+"";break;case"select":i.type=i.type.replace("-group",""),d.length&&d.each(function(e,t){e=e;var n=a.parseAttrs(t.attributes),o=a.attrString(n);r+=""}),t=n+"";break;case"checkbox-group":case"radio-group":var f=!1;i.type=i.type.replace("-group",""),i.other&&(delete i.other,f=!0),d.length&&!function(){var e="checkbox"===i.type?i.name+"[]":i.name,t=void 0;if(d.each(function(n,o){var l=$.extend({},i,a.parseAttrs(o.attributes));l.selected&&(delete l.selected,l.checked=null),l.name=e,l.id=i.id+"-"+n,t=a.attrString(l),r+="
"}),f){var n={id:i.id+"-other",name:e,"class":i["class"]+" other-option"};t=a.attrString($.extend({},i,n)),r+=" '}}(),t=n+'
'+r+"
";break;case"text":case"password":case"email":case"number":case"file":case"hidden":case"date":case"autocomplete":t=n+" ";break;case"color":t=n+" "+o.label.selectColor;break;case"button":case"submit":t="";break;case"checkbox":t=" "+n,i.toggle&&setTimeout(function(){$(document.getElementById(i.id)).kcToggle()},100);break;default:t="<"+i.type+" "+p+">"+u+""}if("hidden"!==i.type){var m=i.id?"form-group field-"+i.id:"";t=a.markup("div",t,{className:m})}else t=a.markup("input",null,i);return t},a.hyphenCase=function(e){return e=e.replace(/[^\w\s\-]/gi,""),e=e.replace(/([A-Z])/g,function(e){return"-"+e.toLowerCase()}),e.replace(/\s/g,"-").replace(/^-+/g,"")},a.attrString=function(e){var t=[];for(var n in e)e.hasOwnProperty(n)&&(n=a.safeAttr(n,e[n]),t.push(n.name+n.value));return t.join(" ")},a.safeAttr=function(e,t){var n={className:"class"};return e=n[e]||e,t=t?window.JSON.stringify(t):!1,t=t?"="+t:"",{name:e,value:t}},a.safeAttrName=function(e){var t={className:"class"};return t[e]||a.hyphenCase(e)},a.parseAttrs=function(e){var t={};for(var n in e)e.hasOwnProperty(n)&&(t[e[n].name]=e[n].value);return t},Element.prototype.appendFormFields=function(e){var t=this;e.reverse();for(var n=e.length-1;n>=0;n--)t.appendChild(e[n])},Element.prototype.emptyContainer=function(){for(var e=this;e.lastChild;)e.removeChild(e.lastChild)};var i=function(){for(var e=document.getElementsByClassName("other-option"),t=function(){var t=document.getElementById(e[n].id+"-value");e[n].onclick=function(e){var n=this;this.checked?(t.style.display="inline-block",n.nextElementSibling.style.display="none",t.oninput=function(e){n.value=this.value}):(t.style.display="none",n.nextElementSibling.style.display="inline-block",t.oninput=void 0)}},n=0;n').insertAfter(t).append(t);o.toggleClass("on",t.is(":checked"));var i='
'+a.labels.on+"
",l='
'+a.labels.off+"
",s='
',c='
'+i+s+l+"
";o.append(c),o.click(function(){t.attr("checked",!t.attr("checked")),e(this).toggleClass("on")})};e.fn.kcToggle=function(n){var r=this;return r.each(function(){var r=e(this);if(!r.data("kcToggle")){var a=new t(r,n);r.data("kcToggle",a)}})}}(jQuery);var _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol?"symbol":typeof e};!function(e){e.fn.formRender=function(e){this.each(function(){var t=new FormRenderFn(e,this);return t})}}(jQuery); \ No newline at end of file diff --git a/demo/assets/js/form-render.min.js.map b/demo/assets/js/form-render.min.js.map index c75d3ae62..7c42f094a 100644 --- a/demo/assets/js/form-render.min.js.map +++ b/demo/assets/js/form-render.min.js.map @@ -1 +1 @@ -{"version":3,"sources":["form-render.min.js","form-render.js","kc-toggle.js"],"names":["FormRenderFn","options","element","formRender","this","defaults","destroyTemplate","container","dataType","formData","label","formRendered","noFormData","other","selectColor","render","notify","error","message","console","success","log","warning","warn","_helpers","opts","$","extend","getElement","id","makeId","document","getElementById","epoch","Date","getTime","tagName","value","markup","tag","content","arguments","length","undefined","attrs","contentType","field","createElement","getContentType","Array","isArray","_typeof","appendContent","string","innerHTML","object","appendChild","array","i","attr","hasOwnProperty","name","safeAttrName","setAttribute","call","fieldRender","fieldMarkup","fieldLabel","optionsMarkup","fieldAttrs","parseAttrs","attributes","fieldLabelText","fieldDesc","description","fieldRequired","fieldOptions","type","subtype","required","fieldLabelVal","fieldAttrsString","attrString","replace","each","index","el","optionAttrs","optionAttrsString","textContent","enableOther","optionName","selected","checked","class","toggle","setTimeout","kcToggle","className","hyphenCase","str","$1","toLowerCase","safeAttr","push","join","window","JSON","stringify","attrNodes","Element","prototype","appendFormFields","fields","reverse","emptyContainer","lastChild","removeChild","otherOptionCB","otherOptions","getElementsByClassName","_loop","otherInput","onclick","evt","option","style","display","nextElementSibling","oninput","runCallbacks","rendered","parseXML","noData","renderedFormWrap","jQuery","_renderedFormWrap","querySelector","parentNode","insertBefore","nextSibling","map","elem","Toggle","theme","labels","off","on","$kcToggle","insertAfter","append","toggleClass","is","kctOn","kctOff","kctHandle","kctInner","click","fn","data","Symbol","iterator","obj","constructor"],"mappings":"AAAA,YCEA,SAASA,cAAaC,EAASC,GAE7B,GAAIC,GAAaC,KACfC,GACEC,iBAAiB,EACjBC,WAAW,EACXC,SAAU,MACVC,UAAU,EACVC,OACEC,aAAc,gBACdC,WAAY,gBACZC,MAAO,QACPC,YAAa,gBAEfC,QAAQ,EACRC,QACEC,MAAO,SAASC,GACd,MAAOC,SAAQF,MAAMC,IAEvBE,QAAS,SAASF,GAChB,MAAOC,SAAQE,IAAIH,IAErBI,QAAS,SAASJ,GAChB,MAAOC,SAAQI,KAAKL,MAI1BM,KAEEC,EAAOC,EAAEC,QAAO,EAAMtB,EAAUJ,EAQpCuB,GAASI,WAAa,WAKpB,MAJK1B,GAAQ2B,KACX3B,EAAQ2B,GAAKL,EAASM,OAAO5B,IAGxB6B,SAASC,eAAe9B,EAAQ2B,KASzCL,EAASM,OAAS,SAAS5B,GACzB,GAAI+B,IAAQ,GAAIC,OAAOC,SAEvB,OAAUjC,GAAQkC,QAAlB,IAA6BH,IAG1BR,EAAKhB,UAAYP,IACpBA,EAAUsB,EAASI,aACnBH,EAAKhB,SAAWP,EAAQmC,OAW1Bb,EAASc,OAAS,SAASC,GAA+B,GAA1BC,GAA0BC,UAAAC,QAAA,GAAAC,SAAAF,UAAA,GAAhB,GAAgBA,UAAA,GAAZG,EAAYH,UAAAC,QAAA,GAAAC,SAAAF,UAAA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AII,IACF2I,MAAO,QACPC,QACEC,IAAK,MACLC,GAAI,OAIJ1H,EAAOC,EAAEC,OAAOtB,EAAUJ,GAC5BmJ,EAAY1H,EAAE,4BAA4B2H,YAAYnJ,GAASoJ,OAAOpJ,EAExEkJ,GAAUG,YAAY,KAAMrJ,EAAQsJ,GAAG,YAEvC,IAAIC,GAAA,uBAA+BhI,EAAKwH,OAAOE,GAA3C,SACAO,EAAA,wBAAiCjI,EAAKwH,OAAOC,IAA7C,SACAS,EAAA,iCACAC,EAAA,0BAAqCH,EAAQE,EAAYD,EAAzD,QAEJN,GAAUE,OAAOM,GAEjBR,EAAUS,MAAM,WACd3J,EAAQyD,KAAK,WAAYzD,EAAQyD,KAAK,YACtCjC,EAAEtB,MAAMmJ,YAAY,QAKxB7H,GAAEoI,GAAG7D,SAAW,SAAShG,GACvB,GAAI8F,GAAS3F,IACb,OAAO2F,GAAOX,KAAK,WACjB,GAAIlF,GAAUwB,EAAEtB,KAChB,KAAIF,EAAQ6J,KAAK,YAAjB,CAGA,GAAI9D,GAAW,GAAI8C,GAAO7I,EAASD,EACnCC,GAAQ6J,KAAK,WAAY9D,QAI5BsC,OFIH,IAAIpF,SAA4B,kBAAX6G,SAAoD,gBAApBA,QAAOC,SAAwB,SAAUC,GAAO,aAAcA,IAAS,SAAUA,GAAO,MAAOA,IAAyB,kBAAXF,SAAyBE,EAAIC,cAAgBH,OAAS,eAAkBE,KC2W1O,SAAUxI,GAERA,EAAEoI,GAAG3J,WAAa,SAASF,GACzBG,KAAKgF,KAAK,WACR,GAAIjF,GAAa,GAAIH,cAAaC,EAASG,KAC3C,OAAOD,OAIVoI","file":"form-render.min.js","sourcesContent":["'use strict';\n\n(function ($) {\n 'use strict';\n\n var Toggle = function Toggle(element, options) {\n\n var defaults = {\n theme: 'fresh',\n labels: {\n off: 'Off',\n on: 'On'\n }\n };\n\n var opts = $.extend(defaults, options),\n $kcToggle = $('
').insertAfter(element).append(element);\n\n $kcToggle.toggleClass('on', element.is(':checked'));\n\n var kctOn = '
' + opts.labels.on + '
',\n kctOff = '
' + opts.labels.off + '
',\n kctHandle = '
',\n kctInner = '
' + kctOn + kctHandle + kctOff + '
';\n\n $kcToggle.append(kctInner);\n\n $kcToggle.click(function () {\n element.attr('checked', !element.attr('checked'));\n $(this).toggleClass('on');\n });\n };\n\n $.fn.kcToggle = function (options) {\n var toggle = this;\n return toggle.each(function () {\n var element = $(this);\n if (element.data('kcToggle')) {\n return;\n }\n var kcToggle = new Toggle(element, options);\n element.data('kcToggle', kcToggle);\n });\n };\n})(jQuery);\n'use strict';\n// render the formBuilder XML into html\n\nvar _typeof = typeof Symbol === \"function\" && typeof Symbol.iterator === \"symbol\" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === \"function\" && obj.constructor === Symbol ? \"symbol\" : typeof obj; };\n\nfunction FormRenderFn(options, element) {\n\n var formRender = this,\n defaults = {\n destroyTemplate: true, // @todo\n container: false,\n dataType: 'xml',\n formData: false,\n label: {\n formRendered: 'Form Rendered',\n noFormData: 'No form data.',\n other: 'Other',\n selectColor: 'Select Color'\n },\n render: true,\n notify: {\n error: function error(message) {\n return console.error(message);\n },\n success: function success(message) {\n return console.log(message);\n },\n warning: function warning(message) {\n return console.warn(message);\n }\n }\n },\n _helpers = {};\n\n var opts = $.extend(true, defaults, options);\n\n /**\n * Require the html element if it has been lost\n *\n * @return {object} javascript object for html element\n */\n _helpers.getElement = function () {\n if (!element.id) {\n element.id = _helpers.makeId(element);\n }\n\n return document.getElementById(element.id);\n };\n\n /**\n * Make an ID for this element using current date and tag\n *\n * @param {Boolean} element\n * @return {String} new id for element\n */\n _helpers.makeId = function (element) {\n var epoch = new Date().getTime();\n\n return element.tagName + '-' + epoch;\n };\n\n if (!opts.formData && element) {\n element = _helpers.getElement();\n opts.formData = element.value;\n }\n\n /**\n * Generate markup wrapper where needed\n *\n * @param {string} tag\n * @param {String|Array|Object} content we wrap this\n * @param {object} attrs\n * @return {String}\n */\n _helpers.markup = function (tag) {\n var content = arguments.length <= 1 || arguments[1] === undefined ? '' : arguments[1];\n var attrs = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2];\n\n var contentType = void 0,\n field = document.createElement(tag),\n getContentType = function getContentType(content) {\n return Array.isArray(content) ? 'array' : typeof content === 'undefined' ? 'undefined' : _typeof(content);\n },\n appendContent = {\n string: function string(content) {\n field.innerHTML = content;\n },\n object: function object(content) {\n return field.appendChild(content);\n },\n array: function array(content) {\n for (var i = 0; i < content.length; i++) {\n contentType = getContentType(content[i]);\n appendContent[contentType](content[i]);\n }\n }\n };\n\n for (var attr in attrs) {\n if (attrs.hasOwnProperty(attr)) {\n var name = _helpers.safeAttrName(attr);\n field.setAttribute(name, attrs[attr]);\n }\n }\n\n contentType = getContentType(content);\n\n if (content) {\n appendContent[contentType].call(this, content);\n }\n\n return field;\n };\n\n /**\n * Generate preview markup\n * @param {object} field\n * @return {string} preview markup for field\n * @todo\n */\n _helpers.fieldRender = function (field) {\n var fieldMarkup = '',\n fieldLabel = '',\n optionsMarkup = '';\n var fieldAttrs = _helpers.parseAttrs(field.attributes),\n fieldLabelText = fieldAttrs.label || '',\n fieldDesc = fieldAttrs.description || '',\n fieldRequired = '',\n fieldOptions = $('option', field);\n fieldAttrs.id = fieldAttrs.name;\n\n fieldAttrs.type = fieldAttrs.subtype || fieldAttrs.type;\n\n if (fieldAttrs.required) {\n fieldAttrs.required = null;\n fieldAttrs['aria-required'] = 'true';\n fieldRequired = '*';\n }\n\n if (fieldAttrs.type !== 'hidden') {\n if (fieldDesc) {\n fieldDesc = '?';\n }\n fieldLabel = '';\n }\n\n var fieldLabelVal = fieldAttrs.label;\n\n delete fieldAttrs.label;\n delete fieldAttrs.description;\n\n var fieldAttrsString = _helpers.attrString(fieldAttrs);\n\n switch (fieldAttrs.type) {\n case 'textarea':\n case 'rich-text':\n delete fieldAttrs.type;\n delete fieldAttrs.value;\n fieldMarkup = fieldLabel + '';\n break;\n case 'select':\n fieldAttrs.type = fieldAttrs.type.replace('-group', '');\n\n if (fieldOptions.length) {\n fieldOptions.each(function (index, el) {\n index = index;\n var optionAttrs = _helpers.parseAttrs(el.attributes),\n optionAttrsString = _helpers.attrString(optionAttrs);\n optionsMarkup += '';\n });\n }\n fieldMarkup = fieldLabel + '';\n break;\n case 'checkbox-group':\n case 'radio-group':\n var enableOther = false;\n fieldAttrs.type = fieldAttrs.type.replace('-group', '');\n\n if (fieldAttrs.other) {\n delete fieldAttrs.other;\n enableOther = true;\n }\n\n if (fieldOptions.length) {\n (function () {\n var optionName = fieldAttrs.type === 'checkbox' ? fieldAttrs.name + '[]' : fieldAttrs.name,\n optionAttrsString = void 0;\n fieldOptions.each(function (index, el) {\n var optionAttrs = $.extend({}, fieldAttrs, _helpers.parseAttrs(el.attributes));\n\n if (optionAttrs.selected) {\n delete optionAttrs.selected;\n optionAttrs.checked = null;\n }\n\n optionAttrs.name = optionName;\n optionAttrs.id = fieldAttrs.id + '-' + index;\n optionAttrsString = _helpers.attrString(optionAttrs);\n optionsMarkup += '
';\n });\n\n if (enableOther) {\n var optionAttrs = {\n id: fieldAttrs.id + '-' + 'other',\n name: optionName,\n class: fieldAttrs.class + ' other-option'\n };\n\n optionAttrsString = _helpers.attrString($.extend({}, fieldAttrs, optionAttrs));\n optionsMarkup += ' ';\n }\n })();\n }\n fieldMarkup = fieldLabel + '
' + optionsMarkup + '
';\n break;\n case 'text':\n case 'password':\n case 'email':\n case 'number':\n case 'file':\n case 'hidden':\n case 'date':\n case 'autocomplete':\n fieldMarkup = fieldLabel + ' ';\n break;\n case 'color':\n fieldMarkup = fieldLabel + ' ' + opts.label.selectColor;\n break;\n case 'button':\n case 'submit':\n fieldMarkup = '';\n break;\n case 'checkbox':\n fieldMarkup = ' ' + fieldLabel;\n\n if (fieldAttrs.toggle) {\n setTimeout(function () {\n $(document.getElementById(fieldAttrs.id)).kcToggle();\n }, 100);\n }\n break;\n default:\n fieldMarkup = '<' + fieldAttrs.type + ' ' + fieldAttrsString + '>' + fieldLabelVal + '';\n }\n\n if (fieldAttrs.type !== 'hidden') {\n var className = fieldAttrs.id ? 'form-group field-' + fieldAttrs.id : '';\n fieldMarkup = _helpers.markup('div', fieldMarkup, {\n className: className\n });\n } else {\n fieldMarkup = _helpers.markup('input', null, fieldAttrs);\n }\n\n return fieldMarkup;\n };\n\n /**\n * Convert camelCase into lowercase-hyphen\n *\n * @param {string} str\n * @return {string}\n */\n _helpers.hyphenCase = function (str) {\n str = str.replace(/[^\\w\\s\\-]/gi, '');\n str = str.replace(/([A-Z])/g, function ($1) {\n return '-' + $1.toLowerCase();\n });\n\n return str.replace(/\\s/g, '-').replace(/^-+/g, '');\n };\n\n _helpers.attrString = function (attrs) {\n var attributes = [];\n\n for (var attr in attrs) {\n if (attrs.hasOwnProperty(attr)) {\n attr = _helpers.safeAttr(attr, attrs[attr]);\n attributes.push(attr.name + attr.value);\n }\n }\n return attributes.join(' ');\n };\n\n _helpers.safeAttr = function (name, value) {\n var safeAttr = {\n className: 'class'\n };\n\n name = safeAttr[name] || name;\n value = value ? window.JSON.stringify(value) : false;\n value = value ? '=' + value : '';\n\n return {\n name: name,\n value: value\n };\n };\n\n _helpers.safeAttrName = function (name) {\n var safeAttr = {\n className: 'class'\n };\n\n return safeAttr[name] || _helpers.hyphenCase(name);\n };\n\n _helpers.parseAttrs = function (attrNodes) {\n var fieldAttrs = {};\n for (var attr in attrNodes) {\n if (attrNodes.hasOwnProperty(attr)) {\n fieldAttrs[attrNodes[attr].name] = attrNodes[attr].value;\n }\n }\n return fieldAttrs;\n };\n\n /**\n * Extend Element prototype to allow us to append fields\n *\n * @param {object} fields Node elements\n */\n Element.prototype.appendFormFields = function (fields) {\n var element = this;\n fields.reverse();\n for (var i = fields.length - 1; i >= 0; i--) {\n element.appendChild(fields[i]);\n }\n };\n\n /**\n * Extend Element prototype to remove content\n */\n Element.prototype.emptyContainer = function () {\n var element = this;\n while (element.lastChild) {\n element.removeChild(element.lastChild);\n }\n };\n\n var otherOptionCB = function otherOptionCB() {\n var otherOptions = document.getElementsByClassName('other-option');\n\n var _loop = function _loop() {\n var otherInput = document.getElementById(otherOptions[i].id + '-value');\n otherOptions[i].onclick = function (evt) {\n var option = this;\n if (this.checked) {\n otherInput.style.display = 'inline-block';\n option.nextElementSibling.style.display = 'none';\n otherInput.oninput = function (evt) {\n option.value = this.value;\n };\n } else {\n otherInput.style.display = 'none';\n option.nextElementSibling.style.display = 'inline-block';\n otherInput.oninput = undefined;\n }\n };\n };\n\n for (var i = 0; i < otherOptions.length; i++) {\n _loop();\n }\n };\n\n var runCallbacks = function runCallbacks() {\n otherOptionCB();\n };\n\n // Begin the core plugin\n var rendered = [];\n\n var formData = $.parseXML(opts.formData),\n fields = $('field', formData);\n // @todo - form configuration settings (control position, creatorId, theme etc)\n // settings = $('settings', formData);\n\n // generate field markup if we have fields\n if (fields.length) {\n fields.each(function (index, field) {\n index = index;\n rendered.push(_helpers.fieldRender(field));\n });\n } else {\n var noData = _helpers.markup('div', opts.label.noFormData, {\n className: 'no-form-data'\n });\n rendered.push(noData);\n opts.notify.error(opts.label.noFormData);\n }\n\n if (opts.render) {\n if (opts.container) {\n var renderedFormWrap = _helpers.markup('div', rendered, { className: 'rendered-form' });\n opts.container = opts.container instanceof jQuery ? opts.container[0] : opts.container;\n opts.container.emptyContainer();\n opts.container.appendChild(renderedFormWrap);\n } else if (element) {\n var _renderedFormWrap = document.querySelector('.rendered-form');\n if (_renderedFormWrap) {\n _renderedFormWrap.emptyContainer();\n _renderedFormWrap.appendFormFields(rendered);\n } else {\n _renderedFormWrap = _helpers.markup('div', rendered, { className: 'rendered-form' });\n element.parentNode.insertBefore(_renderedFormWrap, element.nextSibling);\n element.style.display = 'none';\n element.setAttribute('disabled', 'disabled');\n }\n }\n if (fields.length) {\n runCallbacks(fields);\n opts.notify.success(opts.label.formRendered);\n }\n } else {\n formRender.markup = rendered.map(function (elem) {\n return elem.innerHTML;\n }).join('');\n }\n\n return formRender;\n}\n\n(function ($) {\n\n $.fn.formRender = function (options) {\n this.each(function () {\n var formRender = new FormRenderFn(options, this);\n return formRender;\n });\n };\n})(jQuery);","'use strict';\n// render the formBuilder XML into html\nfunction FormRenderFn(options, element) {\n\n var formRender = this,\n defaults = {\n destroyTemplate: true, // @todo\n container: false,\n dataType: 'xml',\n formData: false,\n label: {\n formRendered: 'Form Rendered',\n noFormData: 'No form data.',\n other: 'Other',\n selectColor: 'Select Color'\n },\n render: true,\n notify: {\n error: function(message) {\n return console.error(message);\n },\n success: function(message) {\n return console.log(message);\n },\n warning: function(message) {\n return console.warn(message);\n }\n }\n },\n _helpers = {};\n\n var opts = $.extend(true, defaults, options);\n\n\n /**\n * Require the html element if it has been lost\n *\n * @return {object} javascript object for html element\n */\n _helpers.getElement = function() {\n if (!element.id) {\n element.id = _helpers.makeId(element);\n }\n\n return document.getElementById(element.id);\n };\n\n /**\n * Make an ID for this element using current date and tag\n *\n * @param {Boolean} element\n * @return {String} new id for element\n */\n _helpers.makeId = function(element) {\n let epoch = new Date().getTime();\n\n return `${element.tagName}-${epoch}`;\n };\n\n if (!opts.formData && element) {\n element = _helpers.getElement();\n opts.formData = element.value;\n }\n\n /**\n * Generate markup wrapper where needed\n *\n * @param {string} tag\n * @param {String|Array|Object} content we wrap this\n * @param {object} attrs\n * @return {String}\n */\n _helpers.markup = function(tag, content = '', attrs = {}) {\n let contentType,\n field = document.createElement(tag),\n getContentType = function(content) {\n return Array.isArray(content) ? 'array' : typeof content;\n },\n appendContent = {\n string: function(content) {\n field.innerHTML = content;\n },\n object: function(content) {\n return field.appendChild(content);\n },\n array: function(content) {\n for (var i = 0; i < content.length; i++) {\n contentType = getContentType(content[i]);\n appendContent[contentType](content[i]);\n }\n }\n };\n\n for (var attr in attrs) {\n if (attrs.hasOwnProperty(attr)) {\n let name = _helpers.safeAttrName(attr);\n field.setAttribute(name, attrs[attr]);\n }\n }\n\n contentType = getContentType(content);\n\n if (content) {\n appendContent[contentType].call(this, content);\n }\n\n return field;\n };\n\n /**\n * Generate preview markup\n * @param {object} field\n * @return {string} preview markup for field\n * @todo\n */\n _helpers.fieldRender = function(field) {\n var fieldMarkup = '',\n fieldLabel = '',\n optionsMarkup = '';\n var fieldAttrs = _helpers.parseAttrs(field.attributes),\n fieldLabelText = fieldAttrs.label || '',\n fieldDesc = fieldAttrs.description || '',\n fieldRequired = '',\n fieldOptions = $('option', field);\n fieldAttrs.id = fieldAttrs.name;\n\n fieldAttrs.type = fieldAttrs.subtype || fieldAttrs.type;\n\n if (fieldAttrs.required) {\n fieldAttrs.required = null;\n fieldAttrs['aria-required'] = 'true';\n fieldRequired = `*`;\n }\n\n if (fieldAttrs.type !== 'hidden') {\n if (fieldDesc) {\n fieldDesc = `?`;\n }\n fieldLabel = ``;\n }\n\n var fieldLabelVal = fieldAttrs.label;\n\n delete fieldAttrs.label;\n delete fieldAttrs.description;\n\n var fieldAttrsString = _helpers.attrString(fieldAttrs);\n\n switch (fieldAttrs.type) {\n case 'textarea':\n case 'rich-text':\n delete fieldAttrs.type;\n delete fieldAttrs.value;\n fieldMarkup = `${fieldLabel}`;\n break;\n case 'select':\n fieldAttrs.type = fieldAttrs.type.replace('-group', '');\n\n if (fieldOptions.length) {\n fieldOptions.each(function(index, el) {\n index = index;\n let optionAttrs = _helpers.parseAttrs(el.attributes),\n optionAttrsString = _helpers.attrString(optionAttrs);\n optionsMarkup += ``;\n });\n }\n fieldMarkup = `${fieldLabel}`;\n break;\n case 'checkbox-group':\n case 'radio-group':\n let enableOther = false;\n fieldAttrs.type = fieldAttrs.type.replace('-group', '');\n\n\n if (fieldAttrs.other) {\n delete fieldAttrs.other;\n enableOther = true;\n }\n\n if (fieldOptions.length) {\n let optionName = fieldAttrs.type === 'checkbox' ? fieldAttrs.name + '[]' : fieldAttrs.name,\n optionAttrsString;\n fieldOptions.each(function(index, el) {\n let optionAttrs = $.extend({}, fieldAttrs, _helpers.parseAttrs(el.attributes));\n\n if (optionAttrs.selected) {\n delete optionAttrs.selected;\n optionAttrs.checked = null;\n }\n\n optionAttrs.name = optionName;\n optionAttrs.id = fieldAttrs.id + '-' + index;\n optionAttrsString = _helpers.attrString(optionAttrs);\n optionsMarkup += `
`;\n });\n\n if (enableOther) {\n let optionAttrs = {\n id: fieldAttrs.id + '-' + 'other',\n name: optionName,\n class: fieldAttrs.class + ' other-option'\n };\n\n optionAttrsString = _helpers.attrString($.extend({}, fieldAttrs, optionAttrs));\n optionsMarkup += ` `;\n }\n\n }\n fieldMarkup = `${fieldLabel}
${optionsMarkup}
`;\n break;\n case 'text':\n case 'password':\n case 'email':\n case 'number':\n case 'file':\n case 'hidden':\n case 'date':\n case 'autocomplete':\n fieldMarkup = `${fieldLabel} `;\n break;\n case 'color':\n fieldMarkup = `${fieldLabel} ${opts.label.selectColor}`;\n break;\n case 'button':\n case 'submit':\n fieldMarkup = ``;\n break;\n case 'checkbox':\n fieldMarkup = ` ${fieldLabel}`;\n\n if (fieldAttrs.toggle) {\n setTimeout(function() {\n $(document.getElementById(fieldAttrs.id)).kcToggle();\n }, 100);\n }\n break;\n default:\n fieldMarkup = `<${fieldAttrs.type} ${fieldAttrsString}>${fieldLabelVal}`;\n }\n\n if (fieldAttrs.type !== 'hidden') {\n let className = fieldAttrs.id ? 'form-group field-' + fieldAttrs.id : '';\n fieldMarkup = _helpers.markup('div', fieldMarkup, {\n className: className\n });\n } else {\n fieldMarkup = _helpers.markup('input', null, fieldAttrs);\n }\n\n return fieldMarkup;\n };\n\n /**\n * Convert camelCase into lowercase-hyphen\n *\n * @param {string} str\n * @return {string}\n */\n _helpers.hyphenCase = (str) => {\n str = str.replace(/[^\\w\\s\\-]/gi, '');\n str = str.replace(/([A-Z])/g, function($1) {\n return '-' + $1.toLowerCase();\n });\n\n return str.replace(/\\s/g, '-').replace(/^-+/g, '');\n };\n\n _helpers.attrString = function(attrs) {\n let attributes = [];\n\n for (var attr in attrs) {\n if (attrs.hasOwnProperty(attr)) {\n attr = _helpers.safeAttr(attr, attrs[attr]);\n attributes.push(attr.name + attr.value);\n }\n }\n return attributes.join(' ');\n };\n\n _helpers.safeAttr = function(name, value) {\n let safeAttr = {\n className: 'class'\n };\n\n name = safeAttr[name] || name;\n value = value ? window.JSON.stringify(value) : false;\n value = value ? `=${value}` : '';\n\n return {\n name,\n value\n };\n };\n\n _helpers.safeAttrName = function(name) {\n let safeAttr = {\n className: 'class'\n };\n\n return safeAttr[name] || _helpers.hyphenCase(name);\n };\n\n _helpers.parseAttrs = function(attrNodes) {\n var fieldAttrs = {};\n for (var attr in attrNodes) {\n if (attrNodes.hasOwnProperty(attr)) {\n fieldAttrs[attrNodes[attr].name] = attrNodes[attr].value;\n }\n }\n return fieldAttrs;\n };\n\n /**\n * Extend Element prototype to allow us to append fields\n *\n * @param {object} fields Node elements\n */\n Element.prototype.appendFormFields = function(fields) {\n var element = this;\n fields.reverse();\n for (var i = fields.length - 1; i >= 0; i--) {\n element.appendChild(fields[i]);\n }\n };\n\n /**\n * Extend Element prototype to remove content\n */\n Element.prototype.emptyContainer = function() {\n var element = this;\n while (element.lastChild) {\n element.removeChild(element.lastChild);\n }\n };\n\n var otherOptionCB = function() {\n var otherOptions = document.getElementsByClassName('other-option');\n for (var i = 0; i < otherOptions.length; i++) {\n let otherInput = document.getElementById(otherOptions[i].id + '-value');\n otherOptions[i].onclick = function(evt) {\n let option = this;\n if (this.checked) {\n otherInput.style.display = 'inline-block';\n option.nextElementSibling.style.display = 'none';\n otherInput.oninput = function(evt) { option.value = this.value; };\n } else {\n otherInput.style.display = 'none';\n option.nextElementSibling.style.display = 'inline-block';\n otherInput.oninput = undefined;\n }\n };\n }\n };\n\n var runCallbacks = function() {\n otherOptionCB();\n };\n\n // Begin the core plugin\n var rendered = [];\n\n var formData = $.parseXML(opts.formData),\n fields = $('field', formData);\n // @todo - form configuration settings (control position, creatorId, theme etc)\n // settings = $('settings', formData);\n\n // generate field markup if we have fields\n if (fields.length) {\n fields.each(function(index, field) {\n index = index;\n rendered.push(_helpers.fieldRender(field));\n });\n } else {\n let noData = _helpers.markup('div', opts.label.noFormData, {\n className: 'no-form-data'\n });\n rendered.push(noData);\n opts.notify.error(opts.label.noFormData);\n }\n\n if (opts.render) {\n if (opts.container) {\n let renderedFormWrap = _helpers.markup('div', rendered, { className: 'rendered-form' });\n opts.container = (opts.container instanceof jQuery) ? opts.container[0] : opts.container;\n opts.container.emptyContainer();\n opts.container.appendChild(renderedFormWrap);\n } else if (element) {\n let renderedFormWrap = document.querySelector('.rendered-form');\n if (renderedFormWrap) {\n renderedFormWrap.emptyContainer();\n renderedFormWrap.appendFormFields(rendered);\n } else {\n renderedFormWrap = _helpers.markup('div', rendered, { className: 'rendered-form' });\n element.parentNode.insertBefore(renderedFormWrap, element.nextSibling);\n element.style.display = 'none';\n element.setAttribute('disabled', 'disabled');\n }\n }\n if (fields.length) {\n runCallbacks(fields);\n opts.notify.success(opts.label.formRendered);\n }\n } else {\n formRender.markup = rendered.map(function(elem) {\n return elem.innerHTML;\n }).join('');\n }\n\n return formRender;\n}\n\n(function($) {\n\n $.fn.formRender = function(options) {\n this.each(function() {\n let formRender = new FormRenderFn(options, this);\n return formRender;\n });\n };\n\n})(jQuery);\n","(function($) {\n 'use strict';\n\n var Toggle = function(element, options) {\n\n var defaults = {\n theme: 'fresh',\n labels: {\n off: 'Off',\n on: 'On'\n }\n };\n\n var opts = $.extend(defaults, options),\n $kcToggle = $('
').insertAfter(element).append(element);\n\n $kcToggle.toggleClass('on', element.is(':checked'));\n\n var kctOn = `
${opts.labels.on}
`,\n kctOff = `
${opts.labels.off}
`,\n kctHandle = `
`,\n kctInner = `
${kctOn}${kctHandle}${kctOff}
`;\n\n $kcToggle.append(kctInner);\n\n $kcToggle.click(function() {\n element.attr('checked', !element.attr('checked'));\n $(this).toggleClass('on');\n });\n\n };\n\n $.fn.kcToggle = function(options) {\n var toggle = this;\n return toggle.each(function() {\n var element = $(this);\n if (element.data('kcToggle')) {\n return;\n }\n var kcToggle = new Toggle(element, options);\n element.data('kcToggle', kcToggle);\n });\n };\n\n})(jQuery);\n"],"sourceRoot":"/source/"} \ No newline at end of file +{"version":3,"sources":["form-render.min.js","form-render.js","kc-toggle.js"],"names":["FormRenderFn","options","element","formRender","this","defaults","destroyTemplate","container","dataType","formData","label","formRendered","noFormData","other","selectColor","render","notify","error","message","console","success","log","warning","warn","_helpers","opts","$","extend","getElement","id","makeId","document","getElementById","epoch","Date","getTime","tagName","value","markup","tag","content","arguments","length","undefined","attrs","contentType","field","createElement","getContentType","Array","isArray","_typeof","appendContent","string","innerHTML","object","appendChild","array","i","attr","hasOwnProperty","name","safeAttrName","setAttribute","call","fieldRender","fieldMarkup","fieldLabel","optionsMarkup","fieldAttrs","parseAttrs","attributes","fieldLabelText","fieldDesc","description","fieldRequired","fieldOptions","type","subtype","required","fieldLabelVal","fieldAttrsString","attrString","replace","each","index","el","optionAttrs","optionAttrsString","textContent","enableOther","optionName","selected","checked","class","toggle","setTimeout","kcToggle","className","hyphenCase","str","$1","toLowerCase","safeAttr","push","join","window","JSON","stringify","attrNodes","Element","prototype","appendFormFields","fields","reverse","emptyContainer","lastChild","removeChild","otherOptionCB","otherOptions","getElementsByClassName","_loop","otherInput","onclick","evt","option","style","display","nextElementSibling","oninput","runCallbacks","rendered","parseXML","noData","renderedFormWrap","jQuery","_renderedFormWrap","querySelector","parentNode","insertBefore","nextSibling","map","elem","Toggle","theme","labels","off","on","$kcToggle","insertAfter","append","toggleClass","is","kctOn","kctOff","kctHandle","kctInner","click","fn","data","Symbol","iterator","obj","constructor"],"mappings":"AAAA,YCEA,SAASA,cAAaC,EAASC,GAE7B,GAAIC,GAAaC,KACfC,GACEC,iBAAiB,EACjBC,WAAW,EACXC,SAAU,MACVC,UAAU,EACVC,OACEC,aAAc,gBACdC,WAAY,gBACZC,MAAO,QACPC,YAAa,gBAEfC,QAAQ,EACRC,QACEC,MAAO,SAASC,GACd,MAAOC,SAAQF,MAAMC,IAEvBE,QAAS,SAASF,GAChB,MAAOC,SAAQE,IAAIH,IAErBI,QAAS,SAAS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AAQ6J,KAAK,WAAY9D,QAI5BsC,OFIH,IAAIpF,SAA4B,kBAAX6G,SAAoD,gBAApBA,QAAOC,SAAwB,SAAUC,GAAO,aAAcA,IAAS,SAAUA,GAAO,MAAOA,IAAyB,kBAAXF,SAAyBE,EAAIC,cAAgBH,OAAS,eAAkBE,KC0W1O,SAAUxI,GAERA,EAAEoI,GAAG3J,WAAa,SAASF,GACzBG,KAAKgF,KAAK,WACR,GAAIjF,GAAa,GAAIH,cAAaC,EAASG,KAC3C,OAAOD,OAIVoI","file":"form-render.min.js","sourcesContent":["'use strict';\n\n(function ($) {\n 'use strict';\n\n var Toggle = function Toggle(element, options) {\n\n var defaults = {\n theme: 'fresh',\n labels: {\n off: 'Off',\n on: 'On'\n }\n };\n\n var opts = $.extend(defaults, options),\n $kcToggle = $('
').insertAfter(element).append(element);\n\n $kcToggle.toggleClass('on', element.is(':checked'));\n\n var kctOn = '
' + opts.labels.on + '
',\n kctOff = '
' + opts.labels.off + '
',\n kctHandle = '
',\n kctInner = '
' + kctOn + kctHandle + kctOff + '
';\n\n $kcToggle.append(kctInner);\n\n $kcToggle.click(function () {\n element.attr('checked', !element.attr('checked'));\n $(this).toggleClass('on');\n });\n };\n\n $.fn.kcToggle = function (options) {\n var toggle = this;\n return toggle.each(function () {\n var element = $(this);\n if (element.data('kcToggle')) {\n return;\n }\n var kcToggle = new Toggle(element, options);\n element.data('kcToggle', kcToggle);\n });\n };\n})(jQuery);\n'use strict';\n// render the formBuilder XML into html\n\nvar _typeof = typeof Symbol === \"function\" && typeof Symbol.iterator === \"symbol\" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === \"function\" && obj.constructor === Symbol ? \"symbol\" : typeof obj; };\n\nfunction FormRenderFn(options, element) {\n\n var formRender = this,\n defaults = {\n destroyTemplate: true, // @todo\n container: false,\n dataType: 'xml',\n formData: false,\n label: {\n formRendered: 'Form Rendered',\n noFormData: 'No form data.',\n other: 'Other',\n selectColor: 'Select Color'\n },\n render: true,\n notify: {\n error: function error(message) {\n return console.error(message);\n },\n success: function success(message) {\n return console.log(message);\n },\n warning: function warning(message) {\n return console.warn(message);\n }\n }\n },\n _helpers = {};\n\n var opts = $.extend(true, defaults, options);\n\n /**\n * Require the html element if it has been lost\n *\n * @return {object} javascript object for html element\n */\n _helpers.getElement = function () {\n if (!element.id) {\n element.id = _helpers.makeId(element);\n }\n\n return document.getElementById(element.id);\n };\n\n /**\n * Make an ID for this element using current date and tag\n *\n * @param {Boolean} element\n * @return {String} new id for element\n */\n _helpers.makeId = function (element) {\n var epoch = new Date().getTime();\n\n return element.tagName + '-' + epoch;\n };\n\n if (!opts.formData && element) {\n element = _helpers.getElement();\n opts.formData = element.value;\n }\n\n /**\n * Generate markup wrapper where needed\n *\n * @param {string} tag\n * @param {String|Array|Object} content we wrap this\n * @param {object} attrs\n * @return {String}\n */\n _helpers.markup = function (tag) {\n var content = arguments.length <= 1 || arguments[1] === undefined ? '' : arguments[1];\n var attrs = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2];\n\n var contentType = void 0,\n field = document.createElement(tag),\n getContentType = function getContentType(content) {\n return Array.isArray(content) ? 'array' : typeof content === 'undefined' ? 'undefined' : _typeof(content);\n },\n appendContent = {\n string: function string(content) {\n field.innerHTML = content;\n },\n object: function object(content) {\n return field.appendChild(content);\n },\n array: function array(content) {\n for (var i = 0; i < content.length; i++) {\n contentType = getContentType(content[i]);\n appendContent[contentType](content[i]);\n }\n }\n };\n\n for (var attr in attrs) {\n if (attrs.hasOwnProperty(attr)) {\n var name = _helpers.safeAttrName(attr);\n field.setAttribute(name, attrs[attr]);\n }\n }\n\n contentType = getContentType(content);\n\n if (content) {\n appendContent[contentType].call(this, content);\n }\n\n return field;\n };\n\n /**\n * Generate preview markup\n * @param {object} field\n * @return {string} preview markup for field\n * @todo\n */\n _helpers.fieldRender = function (field) {\n var fieldMarkup = '',\n fieldLabel = '',\n optionsMarkup = '';\n var fieldAttrs = _helpers.parseAttrs(field.attributes),\n fieldLabelText = fieldAttrs.label || '',\n fieldDesc = fieldAttrs.description || '',\n fieldRequired = '',\n fieldOptions = $('option', field);\n fieldAttrs.id = fieldAttrs.name;\n\n fieldAttrs.type = fieldAttrs.subtype || fieldAttrs.type;\n\n if (fieldAttrs.required) {\n fieldAttrs.required = null;\n fieldAttrs['aria-required'] = 'true';\n fieldRequired = '*';\n }\n\n if (fieldAttrs.type !== 'hidden') {\n if (fieldDesc) {\n fieldDesc = '?';\n }\n fieldLabel = '';\n }\n\n var fieldLabelVal = fieldAttrs.label;\n\n delete fieldAttrs.label;\n delete fieldAttrs.description;\n\n var fieldAttrsString = _helpers.attrString(fieldAttrs);\n\n switch (fieldAttrs.type) {\n case 'textarea':\n case 'rich-text':\n delete fieldAttrs.type;\n fieldMarkup = fieldLabel + '';\n break;\n case 'select':\n fieldAttrs.type = fieldAttrs.type.replace('-group', '');\n\n if (fieldOptions.length) {\n fieldOptions.each(function (index, el) {\n index = index;\n var optionAttrs = _helpers.parseAttrs(el.attributes),\n optionAttrsString = _helpers.attrString(optionAttrs);\n optionsMarkup += '';\n });\n }\n fieldMarkup = fieldLabel + '';\n break;\n case 'checkbox-group':\n case 'radio-group':\n var enableOther = false;\n fieldAttrs.type = fieldAttrs.type.replace('-group', '');\n\n if (fieldAttrs.other) {\n delete fieldAttrs.other;\n enableOther = true;\n }\n\n if (fieldOptions.length) {\n (function () {\n var optionName = fieldAttrs.type === 'checkbox' ? fieldAttrs.name + '[]' : fieldAttrs.name,\n optionAttrsString = void 0;\n fieldOptions.each(function (index, el) {\n var optionAttrs = $.extend({}, fieldAttrs, _helpers.parseAttrs(el.attributes));\n\n if (optionAttrs.selected) {\n delete optionAttrs.selected;\n optionAttrs.checked = null;\n }\n\n optionAttrs.name = optionName;\n optionAttrs.id = fieldAttrs.id + '-' + index;\n optionAttrsString = _helpers.attrString(optionAttrs);\n optionsMarkup += '
';\n });\n\n if (enableOther) {\n var optionAttrs = {\n id: fieldAttrs.id + '-' + 'other',\n name: optionName,\n class: fieldAttrs.class + ' other-option'\n };\n\n optionAttrsString = _helpers.attrString($.extend({}, fieldAttrs, optionAttrs));\n optionsMarkup += ' ';\n }\n })();\n }\n fieldMarkup = fieldLabel + '
' + optionsMarkup + '
';\n break;\n case 'text':\n case 'password':\n case 'email':\n case 'number':\n case 'file':\n case 'hidden':\n case 'date':\n case 'autocomplete':\n fieldMarkup = fieldLabel + ' ';\n break;\n case 'color':\n fieldMarkup = fieldLabel + ' ' + opts.label.selectColor;\n break;\n case 'button':\n case 'submit':\n fieldMarkup = '';\n break;\n case 'checkbox':\n fieldMarkup = ' ' + fieldLabel;\n\n if (fieldAttrs.toggle) {\n setTimeout(function () {\n $(document.getElementById(fieldAttrs.id)).kcToggle();\n }, 100);\n }\n break;\n default:\n fieldMarkup = '<' + fieldAttrs.type + ' ' + fieldAttrsString + '>' + fieldLabelVal + '';\n }\n\n if (fieldAttrs.type !== 'hidden') {\n var className = fieldAttrs.id ? 'form-group field-' + fieldAttrs.id : '';\n fieldMarkup = _helpers.markup('div', fieldMarkup, {\n className: className\n });\n } else {\n fieldMarkup = _helpers.markup('input', null, fieldAttrs);\n }\n\n return fieldMarkup;\n };\n\n /**\n * Convert camelCase into lowercase-hyphen\n *\n * @param {string} str\n * @return {string}\n */\n _helpers.hyphenCase = function (str) {\n str = str.replace(/[^\\w\\s\\-]/gi, '');\n str = str.replace(/([A-Z])/g, function ($1) {\n return '-' + $1.toLowerCase();\n });\n\n return str.replace(/\\s/g, '-').replace(/^-+/g, '');\n };\n\n _helpers.attrString = function (attrs) {\n var attributes = [];\n\n for (var attr in attrs) {\n if (attrs.hasOwnProperty(attr)) {\n attr = _helpers.safeAttr(attr, attrs[attr]);\n attributes.push(attr.name + attr.value);\n }\n }\n return attributes.join(' ');\n };\n\n _helpers.safeAttr = function (name, value) {\n var safeAttr = {\n className: 'class'\n };\n\n name = safeAttr[name] || name;\n value = value ? window.JSON.stringify(value) : false;\n value = value ? '=' + value : '';\n\n return {\n name: name,\n value: value\n };\n };\n\n _helpers.safeAttrName = function (name) {\n var safeAttr = {\n className: 'class'\n };\n\n return safeAttr[name] || _helpers.hyphenCase(name);\n };\n\n _helpers.parseAttrs = function (attrNodes) {\n var fieldAttrs = {};\n for (var attr in attrNodes) {\n if (attrNodes.hasOwnProperty(attr)) {\n fieldAttrs[attrNodes[attr].name] = attrNodes[attr].value;\n }\n }\n return fieldAttrs;\n };\n\n /**\n * Extend Element prototype to allow us to append fields\n *\n * @param {object} fields Node elements\n */\n Element.prototype.appendFormFields = function (fields) {\n var element = this;\n fields.reverse();\n for (var i = fields.length - 1; i >= 0; i--) {\n element.appendChild(fields[i]);\n }\n };\n\n /**\n * Extend Element prototype to remove content\n */\n Element.prototype.emptyContainer = function () {\n var element = this;\n while (element.lastChild) {\n element.removeChild(element.lastChild);\n }\n };\n\n var otherOptionCB = function otherOptionCB() {\n var otherOptions = document.getElementsByClassName('other-option');\n\n var _loop = function _loop() {\n var otherInput = document.getElementById(otherOptions[i].id + '-value');\n otherOptions[i].onclick = function (evt) {\n var option = this;\n if (this.checked) {\n otherInput.style.display = 'inline-block';\n option.nextElementSibling.style.display = 'none';\n otherInput.oninput = function (evt) {\n option.value = this.value;\n };\n } else {\n otherInput.style.display = 'none';\n option.nextElementSibling.style.display = 'inline-block';\n otherInput.oninput = undefined;\n }\n };\n };\n\n for (var i = 0; i < otherOptions.length; i++) {\n _loop();\n }\n };\n\n var runCallbacks = function runCallbacks() {\n otherOptionCB();\n };\n\n // Begin the core plugin\n var rendered = [];\n\n var formData = $.parseXML(opts.formData),\n fields = $('field', formData);\n // @todo - form configuration settings (control position, creatorId, theme etc)\n // settings = $('settings', formData);\n\n // generate field markup if we have fields\n if (fields.length) {\n fields.each(function (index, field) {\n index = index;\n rendered.push(_helpers.fieldRender(field));\n });\n } else {\n var noData = _helpers.markup('div', opts.label.noFormData, {\n className: 'no-form-data'\n });\n rendered.push(noData);\n opts.notify.error(opts.label.noFormData);\n }\n\n if (opts.render) {\n if (opts.container) {\n var renderedFormWrap = _helpers.markup('div', rendered, { className: 'rendered-form' });\n opts.container = opts.container instanceof jQuery ? opts.container[0] : opts.container;\n opts.container.emptyContainer();\n opts.container.appendChild(renderedFormWrap);\n } else if (element) {\n var _renderedFormWrap = document.querySelector('.rendered-form');\n if (_renderedFormWrap) {\n _renderedFormWrap.emptyContainer();\n _renderedFormWrap.appendFormFields(rendered);\n } else {\n _renderedFormWrap = _helpers.markup('div', rendered, { className: 'rendered-form' });\n element.parentNode.insertBefore(_renderedFormWrap, element.nextSibling);\n element.style.display = 'none';\n element.setAttribute('disabled', 'disabled');\n }\n }\n if (fields.length) {\n runCallbacks(fields);\n opts.notify.success(opts.label.formRendered);\n }\n } else {\n formRender.markup = rendered.map(function (elem) {\n return elem.innerHTML;\n }).join('');\n }\n\n return formRender;\n}\n\n(function ($) {\n\n $.fn.formRender = function (options) {\n this.each(function () {\n var formRender = new FormRenderFn(options, this);\n return formRender;\n });\n };\n})(jQuery);","'use strict';\n// render the formBuilder XML into html\nfunction FormRenderFn(options, element) {\n\n var formRender = this,\n defaults = {\n destroyTemplate: true, // @todo\n container: false,\n dataType: 'xml',\n formData: false,\n label: {\n formRendered: 'Form Rendered',\n noFormData: 'No form data.',\n other: 'Other',\n selectColor: 'Select Color'\n },\n render: true,\n notify: {\n error: function(message) {\n return console.error(message);\n },\n success: function(message) {\n return console.log(message);\n },\n warning: function(message) {\n return console.warn(message);\n }\n }\n },\n _helpers = {};\n\n var opts = $.extend(true, defaults, options);\n\n\n /**\n * Require the html element if it has been lost\n *\n * @return {object} javascript object for html element\n */\n _helpers.getElement = function() {\n if (!element.id) {\n element.id = _helpers.makeId(element);\n }\n\n return document.getElementById(element.id);\n };\n\n /**\n * Make an ID for this element using current date and tag\n *\n * @param {Boolean} element\n * @return {String} new id for element\n */\n _helpers.makeId = function(element) {\n let epoch = new Date().getTime();\n\n return `${element.tagName}-${epoch}`;\n };\n\n if (!opts.formData && element) {\n element = _helpers.getElement();\n opts.formData = element.value;\n }\n\n /**\n * Generate markup wrapper where needed\n *\n * @param {string} tag\n * @param {String|Array|Object} content we wrap this\n * @param {object} attrs\n * @return {String}\n */\n _helpers.markup = function(tag, content = '', attrs = {}) {\n let contentType,\n field = document.createElement(tag),\n getContentType = function(content) {\n return Array.isArray(content) ? 'array' : typeof content;\n },\n appendContent = {\n string: function(content) {\n field.innerHTML = content;\n },\n object: function(content) {\n return field.appendChild(content);\n },\n array: function(content) {\n for (var i = 0; i < content.length; i++) {\n contentType = getContentType(content[i]);\n appendContent[contentType](content[i]);\n }\n }\n };\n\n for (var attr in attrs) {\n if (attrs.hasOwnProperty(attr)) {\n let name = _helpers.safeAttrName(attr);\n field.setAttribute(name, attrs[attr]);\n }\n }\n\n contentType = getContentType(content);\n\n if (content) {\n appendContent[contentType].call(this, content);\n }\n\n return field;\n };\n\n /**\n * Generate preview markup\n * @param {object} field\n * @return {string} preview markup for field\n * @todo\n */\n _helpers.fieldRender = function(field) {\n var fieldMarkup = '',\n fieldLabel = '',\n optionsMarkup = '';\n var fieldAttrs = _helpers.parseAttrs(field.attributes),\n fieldLabelText = fieldAttrs.label || '',\n fieldDesc = fieldAttrs.description || '',\n fieldRequired = '',\n fieldOptions = $('option', field);\n fieldAttrs.id = fieldAttrs.name;\n\n fieldAttrs.type = fieldAttrs.subtype || fieldAttrs.type;\n\n if (fieldAttrs.required) {\n fieldAttrs.required = null;\n fieldAttrs['aria-required'] = 'true';\n fieldRequired = `*`;\n }\n\n if (fieldAttrs.type !== 'hidden') {\n if (fieldDesc) {\n fieldDesc = `?`;\n }\n fieldLabel = ``;\n }\n\n var fieldLabelVal = fieldAttrs.label;\n\n delete fieldAttrs.label;\n delete fieldAttrs.description;\n\n var fieldAttrsString = _helpers.attrString(fieldAttrs);\n\n switch (fieldAttrs.type) {\n case 'textarea':\n case 'rich-text':\n delete fieldAttrs.type;\n fieldMarkup = `${fieldLabel}`;\n break;\n case 'select':\n fieldAttrs.type = fieldAttrs.type.replace('-group', '');\n\n if (fieldOptions.length) {\n fieldOptions.each(function(index, el) {\n index = index;\n let optionAttrs = _helpers.parseAttrs(el.attributes),\n optionAttrsString = _helpers.attrString(optionAttrs);\n optionsMarkup += ``;\n });\n }\n fieldMarkup = `${fieldLabel}`;\n break;\n case 'checkbox-group':\n case 'radio-group':\n let enableOther = false;\n fieldAttrs.type = fieldAttrs.type.replace('-group', '');\n\n\n if (fieldAttrs.other) {\n delete fieldAttrs.other;\n enableOther = true;\n }\n\n if (fieldOptions.length) {\n let optionName = fieldAttrs.type === 'checkbox' ? fieldAttrs.name + '[]' : fieldAttrs.name,\n optionAttrsString;\n fieldOptions.each(function(index, el) {\n let optionAttrs = $.extend({}, fieldAttrs, _helpers.parseAttrs(el.attributes));\n\n if (optionAttrs.selected) {\n delete optionAttrs.selected;\n optionAttrs.checked = null;\n }\n\n optionAttrs.name = optionName;\n optionAttrs.id = fieldAttrs.id + '-' + index;\n optionAttrsString = _helpers.attrString(optionAttrs);\n optionsMarkup += `
`;\n });\n\n if (enableOther) {\n let optionAttrs = {\n id: fieldAttrs.id + '-' + 'other',\n name: optionName,\n class: fieldAttrs.class + ' other-option'\n };\n\n optionAttrsString = _helpers.attrString($.extend({}, fieldAttrs, optionAttrs));\n optionsMarkup += ` `;\n }\n\n }\n fieldMarkup = `${fieldLabel}
${optionsMarkup}
`;\n break;\n case 'text':\n case 'password':\n case 'email':\n case 'number':\n case 'file':\n case 'hidden':\n case 'date':\n case 'autocomplete':\n fieldMarkup = `${fieldLabel} `;\n break;\n case 'color':\n fieldMarkup = `${fieldLabel} ${opts.label.selectColor}`;\n break;\n case 'button':\n case 'submit':\n fieldMarkup = ``;\n break;\n case 'checkbox':\n fieldMarkup = ` ${fieldLabel}`;\n\n if (fieldAttrs.toggle) {\n setTimeout(function() {\n $(document.getElementById(fieldAttrs.id)).kcToggle();\n }, 100);\n }\n break;\n default:\n fieldMarkup = `<${fieldAttrs.type} ${fieldAttrsString}>${fieldLabelVal}`;\n }\n\n if (fieldAttrs.type !== 'hidden') {\n let className = fieldAttrs.id ? 'form-group field-' + fieldAttrs.id : '';\n fieldMarkup = _helpers.markup('div', fieldMarkup, {\n className: className\n });\n } else {\n fieldMarkup = _helpers.markup('input', null, fieldAttrs);\n }\n\n return fieldMarkup;\n };\n\n /**\n * Convert camelCase into lowercase-hyphen\n *\n * @param {string} str\n * @return {string}\n */\n _helpers.hyphenCase = (str) => {\n str = str.replace(/[^\\w\\s\\-]/gi, '');\n str = str.replace(/([A-Z])/g, function($1) {\n return '-' + $1.toLowerCase();\n });\n\n return str.replace(/\\s/g, '-').replace(/^-+/g, '');\n };\n\n _helpers.attrString = function(attrs) {\n let attributes = [];\n\n for (var attr in attrs) {\n if (attrs.hasOwnProperty(attr)) {\n attr = _helpers.safeAttr(attr, attrs[attr]);\n attributes.push(attr.name + attr.value);\n }\n }\n return attributes.join(' ');\n };\n\n _helpers.safeAttr = function(name, value) {\n let safeAttr = {\n className: 'class'\n };\n\n name = safeAttr[name] || name;\n value = value ? window.JSON.stringify(value) : false;\n value = value ? `=${value}` : '';\n\n return {\n name,\n value\n };\n };\n\n _helpers.safeAttrName = function(name) {\n let safeAttr = {\n className: 'class'\n };\n\n return safeAttr[name] || _helpers.hyphenCase(name);\n };\n\n _helpers.parseAttrs = function(attrNodes) {\n var fieldAttrs = {};\n for (var attr in attrNodes) {\n if (attrNodes.hasOwnProperty(attr)) {\n fieldAttrs[attrNodes[attr].name] = attrNodes[attr].value;\n }\n }\n return fieldAttrs;\n };\n\n /**\n * Extend Element prototype to allow us to append fields\n *\n * @param {object} fields Node elements\n */\n Element.prototype.appendFormFields = function(fields) {\n var element = this;\n fields.reverse();\n for (var i = fields.length - 1; i >= 0; i--) {\n element.appendChild(fields[i]);\n }\n };\n\n /**\n * Extend Element prototype to remove content\n */\n Element.prototype.emptyContainer = function() {\n var element = this;\n while (element.lastChild) {\n element.removeChild(element.lastChild);\n }\n };\n\n var otherOptionCB = function() {\n var otherOptions = document.getElementsByClassName('other-option');\n for (var i = 0; i < otherOptions.length; i++) {\n let otherInput = document.getElementById(otherOptions[i].id + '-value');\n otherOptions[i].onclick = function(evt) {\n let option = this;\n if (this.checked) {\n otherInput.style.display = 'inline-block';\n option.nextElementSibling.style.display = 'none';\n otherInput.oninput = function(evt) { option.value = this.value; };\n } else {\n otherInput.style.display = 'none';\n option.nextElementSibling.style.display = 'inline-block';\n otherInput.oninput = undefined;\n }\n };\n }\n };\n\n var runCallbacks = function() {\n otherOptionCB();\n };\n\n // Begin the core plugin\n var rendered = [];\n\n var formData = $.parseXML(opts.formData),\n fields = $('field', formData);\n // @todo - form configuration settings (control position, creatorId, theme etc)\n // settings = $('settings', formData);\n\n // generate field markup if we have fields\n if (fields.length) {\n fields.each(function(index, field) {\n index = index;\n rendered.push(_helpers.fieldRender(field));\n });\n } else {\n let noData = _helpers.markup('div', opts.label.noFormData, {\n className: 'no-form-data'\n });\n rendered.push(noData);\n opts.notify.error(opts.label.noFormData);\n }\n\n if (opts.render) {\n if (opts.container) {\n let renderedFormWrap = _helpers.markup('div', rendered, { className: 'rendered-form' });\n opts.container = (opts.container instanceof jQuery) ? opts.container[0] : opts.container;\n opts.container.emptyContainer();\n opts.container.appendChild(renderedFormWrap);\n } else if (element) {\n let renderedFormWrap = document.querySelector('.rendered-form');\n if (renderedFormWrap) {\n renderedFormWrap.emptyContainer();\n renderedFormWrap.appendFormFields(rendered);\n } else {\n renderedFormWrap = _helpers.markup('div', rendered, { className: 'rendered-form' });\n element.parentNode.insertBefore(renderedFormWrap, element.nextSibling);\n element.style.display = 'none';\n element.setAttribute('disabled', 'disabled');\n }\n }\n if (fields.length) {\n runCallbacks(fields);\n opts.notify.success(opts.label.formRendered);\n }\n } else {\n formRender.markup = rendered.map(function(elem) {\n return elem.innerHTML;\n }).join('');\n }\n\n return formRender;\n}\n\n(function($) {\n\n $.fn.formRender = function(options) {\n this.each(function() {\n let formRender = new FormRenderFn(options, this);\n return formRender;\n });\n };\n\n})(jQuery);\n","(function($) {\n 'use strict';\n\n var Toggle = function(element, options) {\n\n var defaults = {\n theme: 'fresh',\n labels: {\n off: 'Off',\n on: 'On'\n }\n };\n\n var opts = $.extend(defaults, options),\n $kcToggle = $('
').insertAfter(element).append(element);\n\n $kcToggle.toggleClass('on', element.is(':checked'));\n\n var kctOn = `
${opts.labels.on}
`,\n kctOff = `
${opts.labels.off}
`,\n kctHandle = `
`,\n kctInner = `
${kctOn}${kctHandle}${kctOff}
`;\n\n $kcToggle.append(kctInner);\n\n $kcToggle.click(function() {\n element.attr('checked', !element.attr('checked'));\n $(this).toggleClass('on');\n });\n\n };\n\n $.fn.kcToggle = function(options) {\n var toggle = this;\n return toggle.each(function() {\n var element = $(this);\n if (element.data('kcToggle')) {\n return;\n }\n var kcToggle = new Toggle(element, options);\n element.data('kcToggle', kcToggle);\n });\n };\n\n})(jQuery);\n"],"sourceRoot":"/source/"} \ No newline at end of file diff --git a/dist/form-render.js b/dist/form-render.js index 7af147bc4..98a568d21 100644 --- a/dist/form-render.js +++ b/dist/form-render.js @@ -441,18 +441,17 @@ function FormRenderFn(options, element) { if (opts.render) { if (opts.container) { - var renderedFormWrap = _helpers.markup('div', rendered, { className: 'rendered-form' }); + var _renderedFormWrap = _helpers.markup('div', rendered, { className: 'rendered-form' }); opts.container = opts.container instanceof jQuery ? opts.container[0] : opts.container; opts.container.emptyContainer(); - opts.container.appendChild(renderedFormWrap); + opts.container.appendChild(_renderedFormWrap); } else if (element) { - var _renderedFormWrap = document.querySelector('.rendered-form'); - if (_renderedFormWrap) { - _renderedFormWrap.emptyContainer(); - _renderedFormWrap.appendFormFields(rendered); + if (element.parentElement.classList.contains('rendered-form')) { + renderedFormWrap.emptyContainer(); + renderedFormWrap.appendFormFields(rendered); } else { - _renderedFormWrap = _helpers.markup('div', rendered, { className: 'rendered-form' }); - element.parentNode.insertBefore(_renderedFormWrap, element.nextSibling); + var _renderedFormWrap2 = _helpers.markup('div', rendered, { className: 'rendered-form' }); + element.parentNode.insertBefore(_renderedFormWrap2, element.nextSibling); element.style.display = 'none'; element.setAttribute('disabled', 'disabled'); } diff --git a/dist/form-render.min.js b/dist/form-render.min.js index 139ef0ea1..ad2d8e02b 100644 --- a/dist/form-render.min.js +++ b/dist/form-render.min.js @@ -3,4 +3,4 @@ formBuilder - https://formbuilder.online/ Version: 1.15.2 Author: Kevin Chappell */ -"use strict";function FormRenderFn(e,t){var n=this,r={destroyTemplate:!0,container:!1,dataType:"xml",formData:!1,label:{formRendered:"Form Rendered",noFormData:"No form data.",other:"Other",selectColor:"Select Color"},render:!0,notify:{error:function(e){return console.error(e)},success:function(e){return console.log(e)},warning:function(e){return console.warn(e)}}},a={},o=$.extend(!0,r,e);a.getElement=function(){return t.id||(t.id=a.makeId(t)),document.getElementById(t.id)},a.makeId=function(e){var t=(new Date).getTime();return e.tagName+"-"+t},!o.formData&&t&&(t=a.getElement(),o.formData=t.value),a.markup=function(e){var t=arguments.length<=1||void 0===arguments[1]?"":arguments[1],n=arguments.length<=2||void 0===arguments[2]?{}:arguments[2],r=void 0,o=document.createElement(e),i=function(e){return Array.isArray(e)?"array":"undefined"==typeof e?"undefined":_typeof(e)},l={string:function(e){o.innerHTML=e},object:function(e){return o.appendChild(e)},array:function(e){for(var t=0;t*'),"hidden"!==i.type&&(s&&(s='?'),n='");var u=i.label;delete i.label,delete i.description;var f=a.attrString(i);switch(i.type){case"textarea":case"rich-text":delete i.type,t=n+"";break;case"select":i.type=i.type.replace("-group",""),d.length&&d.each(function(e,t){e=e;var n=a.parseAttrs(t.attributes),o=a.attrString(n);r+=""}),t=n+"";break;case"checkbox-group":case"radio-group":var p=!1;i.type=i.type.replace("-group",""),i.other&&(delete i.other,p=!0),d.length&&!function(){var e="checkbox"===i.type?i.name+"[]":i.name,t=void 0;if(d.each(function(n,o){var l=$.extend({},i,a.parseAttrs(o.attributes));l.selected&&(delete l.selected,l.checked=null),l.name=e,l.id=i.id+"-"+n,t=a.attrString(l),r+="
"}),p){var n={id:i.id+"-other",name:e,"class":i["class"]+" other-option"};t=a.attrString($.extend({},i,n)),r+=" '}}(),t=n+'
'+r+"
";break;case"text":case"password":case"email":case"number":case"file":case"hidden":case"date":case"autocomplete":t=n+" ";break;case"color":t=n+" "+o.label.selectColor;break;case"button":case"submit":t="";break;case"checkbox":t=" "+n,i.toggle&&setTimeout(function(){$(document.getElementById(i.id)).kcToggle()},100);break;default:t="<"+i.type+" "+f+">"+u+""}if("hidden"!==i.type){var m=i.id?"form-group field-"+i.id:"";t=a.markup("div",t,{className:m})}else t=a.markup("input",null,i);return t},a.hyphenCase=function(e){return e=e.replace(/[^\w\s\-]/gi,""),e=e.replace(/([A-Z])/g,function(e){return"-"+e.toLowerCase()}),e.replace(/\s/g,"-").replace(/^-+/g,"")},a.attrString=function(e){var t=[];for(var n in e)e.hasOwnProperty(n)&&(n=a.safeAttr(n,e[n]),t.push(n.name+n.value));return t.join(" ")},a.safeAttr=function(e,t){var n={className:"class"};return e=n[e]||e,t=t?window.JSON.stringify(t):!1,t=t?"="+t:"",{name:e,value:t}},a.safeAttrName=function(e){var t={className:"class"};return t[e]||a.hyphenCase(e)},a.parseAttrs=function(e){var t={};for(var n in e)e.hasOwnProperty(n)&&(t[e[n].name]=e[n].value);return t},Element.prototype.appendFormFields=function(e){var t=this;e.reverse();for(var n=e.length-1;n>=0;n--)t.appendChild(e[n])},Element.prototype.emptyContainer=function(){for(var e=this;e.lastChild;)e.removeChild(e.lastChild)};var i=function(){for(var e=document.getElementsByClassName("other-option"),t=function(){var t=document.getElementById(e[n].id+"-value");e[n].onclick=function(e){var n=this;this.checked?(t.style.display="inline-block",n.nextElementSibling.style.display="none",t.oninput=function(e){n.value=this.value}):(t.style.display="none",n.nextElementSibling.style.display="inline-block",t.oninput=void 0)}},n=0;n').insertAfter(t).append(t);o.toggleClass("on",t.is(":checked"));var i='
'+a.labels.on+"
",l='
'+a.labels.off+"
",s='
',c='
'+i+s+l+"
";o.append(c),o.click(function(){t.attr("checked",!t.attr("checked")),e(this).toggleClass("on")})};e.fn.kcToggle=function(n){var r=this;return r.each(function(){var r=e(this);if(!r.data("kcToggle")){var a=new t(r,n);r.data("kcToggle",a)}})}}(jQuery);var _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol?"symbol":typeof e};!function(e){e.fn.formRender=function(e){this.each(function(){var t=new FormRenderFn(e,this);return t})}}(jQuery); \ No newline at end of file +"use strict";function FormRenderFn(e,t){var n=this,r={destroyTemplate:!0,container:!1,dataType:"xml",formData:!1,label:{formRendered:"Form Rendered",noFormData:"No form data.",other:"Other",selectColor:"Select Color"},render:!0,notify:{error:function(e){return console.error(e)},success:function(e){return console.log(e)},warning:function(e){return console.warn(e)}}},a={},o=$.extend(!0,r,e);a.getElement=function(){return t.id||(t.id=a.makeId(t)),document.getElementById(t.id)},a.makeId=function(e){var t=(new Date).getTime();return e.tagName+"-"+t},!o.formData&&t&&(t=a.getElement(),o.formData=t.value),a.markup=function(e){var t=arguments.length<=1||void 0===arguments[1]?"":arguments[1],n=arguments.length<=2||void 0===arguments[2]?{}:arguments[2],r=void 0,o=document.createElement(e),i=function(e){return Array.isArray(e)?"array":"undefined"==typeof e?"undefined":_typeof(e)},l={string:function(e){o.innerHTML=e},object:function(e){return o.appendChild(e)},array:function(e){for(var t=0;t*'),"hidden"!==i.type&&(s&&(s='?'),n='");var u=i.label;delete i.label,delete i.description;var p=a.attrString(i);switch(i.type){case"textarea":case"rich-text":delete i.type,t=n+"";break;case"select":i.type=i.type.replace("-group",""),d.length&&d.each(function(e,t){e=e;var n=a.parseAttrs(t.attributes),o=a.attrString(n);r+=""}),t=n+"";break;case"checkbox-group":case"radio-group":var f=!1;i.type=i.type.replace("-group",""),i.other&&(delete i.other,f=!0),d.length&&!function(){var e="checkbox"===i.type?i.name+"[]":i.name,t=void 0;if(d.each(function(n,o){var l=$.extend({},i,a.parseAttrs(o.attributes));l.selected&&(delete l.selected,l.checked=null),l.name=e,l.id=i.id+"-"+n,t=a.attrString(l),r+="
"}),f){var n={id:i.id+"-other",name:e,"class":i["class"]+" other-option"};t=a.attrString($.extend({},i,n)),r+=" '}}(),t=n+'
'+r+"
";break;case"text":case"password":case"email":case"number":case"file":case"hidden":case"date":case"autocomplete":t=n+" ";break;case"color":t=n+" "+o.label.selectColor;break;case"button":case"submit":t="";break;case"checkbox":t=" "+n,i.toggle&&setTimeout(function(){$(document.getElementById(i.id)).kcToggle()},100);break;default:t="<"+i.type+" "+p+">"+u+""}if("hidden"!==i.type){var m=i.id?"form-group field-"+i.id:"";t=a.markup("div",t,{className:m})}else t=a.markup("input",null,i);return t},a.hyphenCase=function(e){return e=e.replace(/[^\w\s\-]/gi,""),e=e.replace(/([A-Z])/g,function(e){return"-"+e.toLowerCase()}),e.replace(/\s/g,"-").replace(/^-+/g,"")},a.attrString=function(e){var t=[];for(var n in e)e.hasOwnProperty(n)&&(n=a.safeAttr(n,e[n]),t.push(n.name+n.value));return t.join(" ")},a.safeAttr=function(e,t){var n={className:"class"};return e=n[e]||e,t=t?window.JSON.stringify(t):!1,t=t?"="+t:"",{name:e,value:t}},a.safeAttrName=function(e){var t={className:"class"};return t[e]||a.hyphenCase(e)},a.parseAttrs=function(e){var t={};for(var n in e)e.hasOwnProperty(n)&&(t[e[n].name]=e[n].value);return t},Element.prototype.appendFormFields=function(e){var t=this;e.reverse();for(var n=e.length-1;n>=0;n--)t.appendChild(e[n])},Element.prototype.emptyContainer=function(){for(var e=this;e.lastChild;)e.removeChild(e.lastChild)};var i=function(){for(var e=document.getElementsByClassName("other-option"),t=function(){var t=document.getElementById(e[n].id+"-value");e[n].onclick=function(e){var n=this;this.checked?(t.style.display="inline-block",n.nextElementSibling.style.display="none",t.oninput=function(e){n.value=this.value}):(t.style.display="none",n.nextElementSibling.style.display="inline-block",t.oninput=void 0)}},n=0;n').insertAfter(t).append(t);o.toggleClass("on",t.is(":checked"));var i='
'+a.labels.on+"
",l='
'+a.labels.off+"
",s='
',c='
'+i+s+l+"
";o.append(c),o.click(function(){t.attr("checked",!t.attr("checked")),e(this).toggleClass("on")})};e.fn.kcToggle=function(n){var r=this;return r.each(function(){var r=e(this);if(!r.data("kcToggle")){var a=new t(r,n);r.data("kcToggle",a)}})}}(jQuery);var _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol?"symbol":typeof e};!function(e){e.fn.formRender=function(e){this.each(function(){var t=new FormRenderFn(e,this);return t})}}(jQuery); \ No newline at end of file diff --git a/src/js/form-render.js b/src/js/form-render.js index cc50ed067..ad79dc723 100644 --- a/src/js/form-render.js +++ b/src/js/form-render.js @@ -384,12 +384,11 @@ function FormRenderFn(options, element) { opts.container.emptyContainer(); opts.container.appendChild(renderedFormWrap); } else if (element) { - let renderedFormWrap = document.querySelector('.rendered-form'); - if (renderedFormWrap) { + if (element.parentElement.classList.contains('rendered-form')) { renderedFormWrap.emptyContainer(); renderedFormWrap.appendFormFields(rendered); } else { - renderedFormWrap = _helpers.markup('div', rendered, { className: 'rendered-form' }); + let renderedFormWrap = _helpers.markup('div', rendered, { className: 'rendered-form' }); element.parentNode.insertBefore(renderedFormWrap, element.nextSibling); element.style.display = 'none'; element.setAttribute('disabled', 'disabled');