Commit e8e2302a by Luciano Barletta

generate json

1 parent edd14dee
/**
* Armado de formulario
*/
function removeField(b){ function removeField(b){
let div = b.parentElement; let div = b.parentElement;
let tab = div.parentElement; let tab = div.parentElement;
...@@ -5,7 +8,8 @@ function removeField(b){ ...@@ -5,7 +8,8 @@ function removeField(b){
} }
function addField(b){ function addField(b){
let newfield = document.createElement("div") let newfield = document.createElement("div");
newfield.setAttribute("name","Field");
newfield.innerHTML = document.getElementById("fieldTemplate").innerHTML; newfield.innerHTML = document.getElementById("fieldTemplate").innerHTML;
b.parentElement.appendChild(newfield); b.parentElement.appendChild(newfield);
} }
...@@ -17,7 +21,40 @@ function removeTab(b){ ...@@ -17,7 +21,40 @@ function removeTab(b){
} }
function addTab(t){ function addTab(t){
let newtab = document.createElement("div") let newtab = document.createElement("div");
newtab.setAttribute("name","Tab");
newtab.innerHTML = document.getElementById("tabTemplate").innerHTML; newtab.innerHTML = document.getElementById("tabTemplate").innerHTML;
t.appendChild(newtab); t.appendChild(newtab);
} }
/**
* Lectura de información y formateado
*/
function processField(field){
return {
'Title' : field.children[0],
'Input' : field.children[1].selectedOptions[0].value,
'Required' : field.children[2].checked,
};
}
function processTab(tab){
let dict = {};
for(let i = 0; i < tab.children.length; i++){
if (tab.children[i].getAttribute("name") == "Field"){
dict[i] = processField(tab.children[i]);
}
}
return dict;
}
function generate(tabs){
let dict = {};
for(let i = 0; i < tabs.children.length; i++){
if (tabs.children[i].getAttribute("name") == "Tab"){
dict[i] = processTab(tabs.children[i]);
}
}
console.log(JSON.stringify(dict));
}
...@@ -14,6 +14,12 @@ ...@@ -14,6 +14,12 @@
<button onclick="addTab(document.getElementById('tabs'))"> <button onclick="addTab(document.getElementById('tabs'))">
+ +
</button> </button>
<br>
<br>
<button onclick="generate(document.getElementById('tabs'))">
Generar
</button>
</body> </body>
<!-- templates --> <!-- templates -->
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!