Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
Luciano Barletta
/
mini-web
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
Commit 821f6931
authored
2019-11-27 13:26:45 +0000
by
Luciano Barletta
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
validation
1 parent
1f0ee314
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
88 additions
and
2 deletions
Geo/Scripts/construct.js
Geo/generate.html
Luciano/static/Scripts/construct.js
Luciano/templates/generate.html
Geo/Scripts/construct.js
View file @
821f693
...
...
@@ -70,7 +70,9 @@ function processField(field){
function
processTab
(
tab
){
let
dict
=
[];
let
container
=
getDescendantByAttribute
(
tab
,
"name"
,
"Field"
).
parentElement
;
let
container
=
getDescendantByAttribute
(
tab
,
"name"
,
"Field"
);
if
(
container
==
null
)
return
dict
;
container
=
container
.
parentElement
;
for
(
let
i
=
0
;
i
<
container
.
children
.
length
;
i
++
){
if
(
container
.
children
[
i
].
getAttribute
(
"name"
)
==
"Field"
)
{
dict
.
push
(
processField
(
container
.
children
[
i
]));
...
...
@@ -112,4 +114,44 @@ function maxChild(container,number){
(
a
,
b
)
=>
fixinput
(
a
)
>
fixinput
(
b
)
?
a
:
b
);
return
fixinput
(
max
);
}
function
validate
(
obj
){
const
internal
=
"Hubo un error en la generación del formulario"
;
if
(
typeof
obj
!=
"object"
)
return
triggerError
(
internal
,
"not object"
);
for
(
let
t_it
=
0
;
t_it
<
obj
.
length
;
t_it
++
)
{
let
tab
=
obj
[
t_it
];
if
(
"Title"
in
tab
&&
"Fields"
in
tab
){
if
(
typeof
tab
.
Title
!=
"string"
)
return
triggerError
(
internal
,
"wrong type in tab title"
);
if
(
typeof
tab
.
Fields
!=
"object"
)
return
triggerError
(
internal
,
"wrong type in tab fields"
);
if
(
tab
.
Title
==
""
)
return
triggerError
(
"La tab "
+
(
t_it
+
1
)
+
" necesita un título"
,
"empty tab title"
);
if
(
tab
.
Fields
.
length
==
0
)
return
triggerError
(
"La tab "
+
(
t_it
+
1
)
+
" requiere campos"
,
"empty tab fields"
);
for
(
let
f_it
=
0
;
f_it
<
tab
.
Fields
.
length
;
f_it
++
)
{
let
field
=
tab
.
Fields
[
f_it
];
if
(
"Title"
in
field
&&
"Input"
in
field
&&
"Required"
in
field
)
{
if
(
typeof
field
.
Title
!=
"string"
)
return
triggerError
(
internal
,
"wrong type in field title"
);
if
(
typeof
field
.
Input
!=
"string"
)
return
triggerError
(
internal
,
"wrong type in field input"
);
if
(
typeof
field
.
Required
!=
"boolean"
)
return
triggerError
(
internal
,
"wrong type in field required"
);
if
(
field
.
Title
==
""
)
return
triggerError
(
"El campo "
+
(
f_it
+
1
)
+
" del tab "
+
(
t_it
+
1
)
+
" necesita un título"
,
"empty field title"
);
if
(
field
.
Input
==
""
)
return
triggerError
(
"El campo "
+
(
f_it
+
1
)
+
" del tab "
+
(
t_it
+
1
)
+
" necesita un input"
,
"empty field input"
);
}
else
{
return
triggerError
(
internal
,
"field lacks property"
)
}
}
}
else
{
return
triggerError
(
internal
,
"tab lacks property"
)
}
}
}
function
triggerError
(
type
,
log
){
let
out
=
"triggerError => \nerror_message = "
+
type
;
if
(
log
)
out
+=
"\nlog_message = "
+
log
;
console
.
log
(
out
);
document
.
getElementById
(
"ErrorMessage"
).
innerText
=
type
;
}
\ No newline at end of file
Geo/generate.html
View file @
821f693
...
...
@@ -25,6 +25,7 @@
+
</button>
</div>
<p
id=
"ErrorMessage"
style=
"font-weight: bold; text-align: center; color: red;"
></p>
<h3
id=
"ContinuarText"
>
Cuando se encuentre conforme con el formulario presione Continuar
</h3>
<button
id=
"ContinuarButton"
onclick=
"ArmarForm( generate(document.getElementById('tabs')) )"
>
Continuar
</button>
</section>
...
...
Luciano/static/Scripts/construct.js
View file @
821f693
...
...
@@ -70,7 +70,9 @@ function processField(field){
function
processTab
(
tab
){
let
dict
=
[];
let
container
=
getDescendantByAttribute
(
tab
,
"name"
,
"Field"
).
parentElement
;
let
container
=
getDescendantByAttribute
(
tab
,
"name"
,
"Field"
);
if
(
container
==
null
)
return
dict
;
container
=
container
.
parentElement
;
for
(
let
i
=
0
;
i
<
container
.
children
.
length
;
i
++
){
if
(
container
.
children
[
i
].
getAttribute
(
"name"
)
==
"Field"
)
{
dict
.
push
(
processField
(
container
.
children
[
i
]));
...
...
@@ -112,4 +114,44 @@ function maxChild(container,number){
(
a
,
b
)
=>
fixinput
(
a
)
>
fixinput
(
b
)
?
a
:
b
);
return
fixinput
(
max
);
}
function
validate
(
obj
){
const
internal
=
"Hubo un error en la generación del formulario"
;
if
(
typeof
obj
!=
"object"
)
return
triggerError
(
internal
,
"not object"
);
for
(
let
t_it
=
0
;
t_it
<
obj
.
length
;
t_it
++
)
{
let
tab
=
obj
[
t_it
];
if
(
"Title"
in
tab
&&
"Fields"
in
tab
){
if
(
typeof
tab
.
Title
!=
"string"
)
return
triggerError
(
internal
,
"wrong type in tab title"
);
if
(
typeof
tab
.
Fields
!=
"object"
)
return
triggerError
(
internal
,
"wrong type in tab fields"
);
if
(
tab
.
Title
==
""
)
return
triggerError
(
"La tab "
+
(
t_it
+
1
)
+
" necesita un título"
,
"empty tab title"
);
if
(
tab
.
Fields
.
length
==
0
)
return
triggerError
(
"La tab "
+
(
t_it
+
1
)
+
" requiere campos"
,
"empty tab fields"
);
for
(
let
f_it
=
0
;
f_it
<
tab
.
Fields
.
length
;
f_it
++
)
{
let
field
=
tab
.
Fields
[
f_it
];
if
(
"Title"
in
field
&&
"Input"
in
field
&&
"Required"
in
field
)
{
if
(
typeof
field
.
Title
!=
"string"
)
return
triggerError
(
internal
,
"wrong type in field title"
);
if
(
typeof
field
.
Input
!=
"string"
)
return
triggerError
(
internal
,
"wrong type in field input"
);
if
(
typeof
field
.
Required
!=
"boolean"
)
return
triggerError
(
internal
,
"wrong type in field required"
);
if
(
field
.
Title
==
""
)
return
triggerError
(
"El campo "
+
(
f_it
+
1
)
+
" del tab "
+
(
t_it
+
1
)
+
" necesita un título"
,
"empty field title"
);
if
(
field
.
Input
==
""
)
return
triggerError
(
"El campo "
+
(
f_it
+
1
)
+
" del tab "
+
(
t_it
+
1
)
+
" necesita un input"
,
"empty field input"
);
}
else
{
return
triggerError
(
internal
,
"field lacks property"
)
}
}
}
else
{
return
triggerError
(
internal
,
"tab lacks property"
)
}
}
}
function
triggerError
(
type
,
log
){
let
out
=
"triggerError => \nerror_message = "
+
type
;
if
(
log
)
out
+=
"\nlog_message = "
+
log
;
console
.
log
(
out
);
document
.
getElementById
(
"ErrorMessage"
).
innerText
=
type
;
}
\ No newline at end of file
Luciano/templates/generate.html
View file @
821f693
...
...
@@ -25,6 +25,7 @@
+
</button>
</div>
<p
id=
"ErrorMessage"
style=
"font-weight: bold; text-align: center; color: red;"
></p>
<h3
id=
"ContinuarText"
>
Cuando se encuentre conforme con el formulario presione Continuar
</h3>
<button
id=
"ContinuarButton"
onclick=
"ArmarForm( generate(document.getElementById('tabs')) )"
>
Continuar
</button>
</section>
...
...
Write
Preview
Styling with
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment