NxTIC/js/lib/form-builder/main.js

77 lines
2.2 KiB
JavaScript

/* [0] On efface le <body>
=========================================================*/
document.body.innerHTML = '';
"use strict";
var default_definition = {
'input': { node_type: 'input', node_attr: '{__attributes__}' },
'h/^([1-6])$/': { node_type: 'h{$1}', node_attr: '{__attributes__}', node_children: '{__children__}' },
'br': { node_type: 'br', },
'option': { node_type: 'option', node_attr: '{__attributes__}', node_children: '{__children__}' },
'select': { node_type: 'select', node_attr: '{__attributes__}', node_children: '{__children__}' },
'span': { node_type: 'span', node_attr: '{__attributes__}', node_children: '{__children__}' }
};
var custom_definition = {
'input:/^([a-z]+)$/': {
node: 'input',
attributes: {
'type': '{$1}',
'data-name': '{name}',
'value': '{value}',
'placeholder': '{placeholder}'
},
next_nodes: [{ node: 'br' }]
},
'custom-select': {
node: 'span',
attributes: { 'class': 'select-container nobold' },
children: [
{
node: 'select',
attributes: { 'data-name': '{name}' },
children: [
{
node: 'option',
attribute: { value: '{options.value}' },
text: '{options.value}',
repeat: '{{options}}'
}
]
}
],
next_nodes: [{ node: 'br' }]
}
};
var 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: 'number', $value: '{number}' },
{ node: 'custom-select', $name: 'existing', $$options: '{{options}}' }
]
};
var fb = new FormBuilder(document.body, form);
fb.add_definition(default_definition);
fb.add_definition(custom_definition);