diff --git a/js/lib/form-builder-min.js b/js/lib/form-builder-min.js index e1f2c90..893b720 100644 --- a/js/lib/form-builder-min.js +++ b/js/lib/form-builder-min.js @@ -14,6 +14,6 @@ FormBuilder.replaceStatementsArrayValue=function(a,b,f,d){b=FormBuilder.regex.ar FormBuilder.readRef=function(a,b){var f,d="";if("string"==typeof b&&FormBuilder.regex.ref_pri.test(b)){for(;"string"==typeof b&&FormBuilder.regex.ref_pri.test(b);)b=a[b],b instanceof Array&&1==b.length&&(b=b[0]);return b}for(f in b)d=FormBuilder.regex.ref_pri.test(b[f])&&a.hasOwnProperty(b[f])?a[b[f]]instanceof Array?d+FormBuilder.readRef(a,a[b[f]]):d+a[b[f]]:d+b[f].toString();return d}; FormBuilder.buildElements=function(a,b,f){var d=[],e,c,k,g,h,l=["NULL"],n;if(a.hasOwnProperty("repeat")&&(g=FormBuilder.readRef(b,a.repeat.n),!isNaN(g)))for(l=[],f.hasOwnProperty(a.repeat.id+":i")||(f[a.repeat.id+":i"]=ref(0)),f.hasOwnProperty(a.repeat.id+":n")||(f[a.repeat.id+":n"]=ref(g)),e=0;e, on ajoute la valeur (si elle existe) */ + /* (1) Si référence, on ajoute la valeur (si elle existe) */ if( FormBuilder.regex.ref_pri.test(parts[i]) && ref_table.hasOwnProperty(parts[i]) ){ // si le résultat est un tableau, on lance récursivement @@ -953,6 +953,7 @@ FormBuilder.buildElements = function(definition, ref_table, ref_assoc){ repeated[i] = {}; + // Pour chaque champ, on récupère/calcule la valeur for( j in scope ){ // {1} Si la valeur est un attribut // @@ -961,7 +962,7 @@ FormBuilder.buildElements = function(definition, ref_table, ref_assoc){ // {2} Si c'est une fonction custom // else if( funcs.hasOwnProperty(scope[j]) ) - repeated[i][definition.browse.id+'.'+scope[j]] = funcs[scope[j]](tmp[i]); + repeated[i][definition.browse.id+'.'+scope[j]] = funcs[ scope[j] ]( tmp[i] ); } @@ -984,8 +985,12 @@ FormBuilder.buildElements = function(definition, ref_table, ref_assoc){ built[b] = { prev: [], node: null, next: [] }; /* (2) Gestion des variables de 'repeat' et 'browse' */ - for( i in repeated[b] ) - ref_table[ ref_assoc[i] ] = repeated[b][i]; + if( repeated[b] instanceof Object ){ + + for( i in repeated[b] ) + ref_table[ ref_assoc[i] ] = repeated[b][i]; + + } @@ -1046,7 +1051,7 @@ FormBuilder.buildElements = function(definition, ref_table, ref_assoc){ if( definition.hasOwnProperty('text') ){ // Note: Override les enfants - built[b].node.innerHTML = definition.text; + built[b].node.innerHTML = FormBuilder.readRef(ref_table, definition.text); } diff --git a/js/lib/form-builder/main-min.js b/js/lib/form-builder/main-min.js index d9a530c..8b054e6 100644 --- a/js/lib/form-builder/main-min.js +++ b/js/lib/form-builder/main-min.js @@ -1,5 +1,5 @@ document.body.innerHTML="";"use strict"; var default_definition={input:{node_type:"input"},"/^h([1-6])$/":{node_type:"h{$1}"},br:{node_type:"br"},option:{node_type:"option"},select:{node_type:"select"},span:{node_type:"span"}},custom_definition={"/^input.([a-z]+)$/":{node:"input",attributes:{type:"{$1}","data-name":"{name}",value:"{value}",placeholder:"{placeholder}"},next_nodes:[{node:"br"}],listeners:{focus:"{xx()}"}},"custom-select":{node:"span",attributes:{"class":"select-container nobold"},children:[{node:"select",attributes:{"data-name":"{name}"}, -children:[{node:"option",attributes:{value:"{options.id}"},text:"{options.value}",browse:{array:"{options[]}",funcs:{"options.value":"{getval()}","options.id":"{getnam()}"}}}]}],next_nodes:[{node:"br"}]}},form={node:"h4",attributes:{"data-icon":"o","class":"new-contact color2"},children:[{node:"input.hidden",$name:"uid",$value:"{uid}"},{node:"input.hidden",$name:"call",$value:"{call}"},{node:"input.hidden",$name:"sms",$value:"{sms}"},{node:"input.hidden",$name:"countcall",$value:"{countcall}"},{node:"input.hidden", -$name:"countsms",$value:"{countsms}"},{node:"input.text",$name:"total",$value:"xx{countcall} calls + {countsms} sms to {number}xx"},{node:"input.text",$name:"count{rep:i}",$value:"{rep:i} sur {rep:n}",repeat:{n:10,id:"rep"}},{node:"input.text",$name:"number",$value:"{number}",$xx:"{clicklistener}"},{node:"custom-select",$name:"existing",$options:"{options[]}"}]},fb=new FormBuilder(form);fb.add_definition(default_definition);fb.add_definition(custom_definition); +children:[{node:"option",attributes:{value:"{options.id}"},text:"{options.value} - {options:i}/{options:n}",browse:{array:"{options[]}",funcs:{"options.value":"{getval()}","options.id":"{getnam()}"}}}]}],next_nodes:[{node:"br"}]}},form={node:"h4",attributes:{"data-icon":"o","class":"new-contact color2"},children:[{node:"input.hidden",$name:"uid",$value:"{uid}"},{node:"input.hidden",$name:"call",$value:"{call}"},{node:"input.hidden",$name:"sms",$value:"{sms}"},{node:"input.hidden",$name:"countcall", +$value:"{countcall}"},{node:"input.hidden",$name:"countsms",$value:"{countsms}"},{node:"input.text",$name:"total",$value:"xx{countcall} calls + {countsms} sms to {number}xx"},{node:"input.text",$name:"count{rep:i}",$value:"{rep:i} sur {rep:n}",repeat:{n:10,id:"rep"}},{node:"input.text",$name:"number",$value:"{number}",$xx:"{clicklistener}"},{node:"custom-select",$name:"existing",$options:"{options[]}"}]},fb=new FormBuilder(form);fb.add_definition(default_definition);fb.add_definition(custom_definition); fb.build({uid:1,call:2,sms:3,countcall:4,countsms:5,number:"01 02 03 04 05",options:["a","b","c","d"],clicklistener:function(a){console.log("clicked",a)},getval:function(a){return a},getnam:function(a){return"["+a+"]"}});console.log(fb.built_form);var str=function(a){return FormBuilder.readRef(fb.ref_table,a)};fb.attach(document.body); diff --git a/js/lib/form-builder/main.js b/js/lib/form-builder/main.js index e43af50..83f8445 100644 --- a/js/lib/form-builder/main.js +++ b/js/lib/form-builder/main.js @@ -41,7 +41,7 @@ var custom_definition = { { node: 'option', attributes: { value: '{options.id}' }, - text: '{options.value}', + text: '{options.value} - {options:i}/{options:n}', browse: { array: '{options[]}', funcs: {