Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
R
rjs_json_form
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Rafael Monnerat
rjs_json_form
Commits
e51a0e05
Commit
e51a0e05
authored
Apr 26, 2018
by
Boris Kocherov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
checkValidity(): fix error and improve invalid state information
parent
acc0d2b0
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
59 additions
and
24 deletions
+59
-24
gadget_json_generated_form.js
gadget_json_generated_form.js
+59
-24
No files found.
gadget_json_generated_form.js
View file @
e51a0e05
/*jslint nomen: true, maxlen: 200, indent: 2, maxerr: 100*/
/*global window, document, URL, rJS, RSVP, jIO, tv4 */
/*global window, document, URL, rJS, RSVP, jIO, tv4
, location
*/
(
function
(
window
,
document
,
rJS
,
RSVP
,
jIO
,
tv4
)
{
(
function
(
window
,
document
,
location
,
rJS
,
RSVP
,
jIO
,
tv4
)
{
"
use strict
"
;
var
render_object
,
expandSchema
;
...
...
@@ -1416,11 +1416,19 @@
return
tv4
.
validateMultiple
(
json_d
,
g
.
props
.
schema
[
""
]);
})
.
push
(
function
(
validation
)
{
var
index
,
tasks
=
[];
var
i
,
error_id
,
error
,
span
,
tasks
=
[],
errors_block
=
g
.
element
.
querySelector
(
"
div.error-block
"
);
if
(
errors_block
)
{
errors_block
.
parentNode
.
removeChild
(
errors_block
);
}
g
.
element
.
querySelectorAll
(
"
.error
"
).
forEach
(
function
(
error_message
)
{
error_message
.
textContent
=
""
;
error_message
.
removeAttribute
(
"
id
"
);
error_message
.
hidden
=
true
;
});
...
...
@@ -1433,37 +1441,58 @@
return
false
;
});
}
function
print_error
(
message
)
{
span
=
document
.
createElement
(
"
span
"
);
span
.
setAttribute
(
"
class
"
,
"
error
"
);
span
.
textContent
=
"
errors:
"
;
errors_block
=
document
.
createElement
(
"
div
"
);
errors_block
.
setAttribute
(
"
class
"
,
"
subfield error-block
"
);
errors_block
.
appendChild
(
span
);
function
print_error
(
error
,
errorUid
,
errorId
)
{
return
function
(
element
)
{
var
id
=
element
.
id
,
error_message
;
error_message
,
a
=
document
.
createElement
(
"
a
"
);
a
.
setAttribute
(
"
href
"
,
"
#
"
+
errorUid
);
a
.
text
=
errorId
;
element
.
setAttribute
(
"
class
"
,
"
error-input
"
);
error_message
=
element
.
querySelector
(
"
#
"
+
id
.
replace
(
"
/
"
,
"
\\
/
"
)
+
"
> .error
"
);
error_message
.
textContent
=
message
;
error_message
.
appendChild
(
a
);
error_message
.
setAttribute
(
"
id
"
,
errorUid
);
error_message
.
appendChild
(
document
.
createTextNode
(
error
.
message
));
error_message
.
hidden
=
false
;
a
=
document
.
createElement
(
"
a
"
);
a
.
text
=
errorId
;
a
.
setAttribute
(
"
data-error-link
"
,
"
#
"
+
errorUid
);
a
.
setAttribute
(
"
class
"
,
"
error-link
"
);
errors_block
.
appendChild
(
a
);
};
}
for
(
index
in
validation
.
errors
)
{
if
(
validation
.
errors
.
hasOwnProperty
(
index
))
{
for
(
i
=
0
;
i
<
validation
.
errors
.
length
;
i
+=
1
)
{
error
=
validation
.
errors
[
i
];
error_id
=
(
i
+
1
).
toString
();
tasks
.
push
(
g
.
getElementByPath
(
validation
.
errors
[
index
].
dataPath
)
.
push
(
print_error
(
validation
.
errors
[
index
].
message
))
g
.
getElementByPath
(
error
.
dataPath
||
"
/
"
)
.
push
(
print_error
(
error
,
"
error
"
+
error_id
,
error_id
))
);
}
}
for
(
index
in
validation
.
missing
)
{
if
(
validation
.
missing
.
hasOwnProperty
(
index
))
{
for
(
i
=
0
;
i
<
validation
.
missing
.
length
;
i
+=
1
)
{
error
=
validation
.
missing
[
i
];
error_id
=
(
i
+
1
).
toString
();
tasks
.
push
(
g
.
getElementByPath
(
validation
.
missing
[
index
].
dataPath
)
.
push
(
print_error
(
validation
.
missing
[
index
].
message
))
g
.
getElementByPath
(
error
.
dataPath
||
"
/
"
)
.
push
(
print_error
(
error
,
"
missing
"
+
error_id
,
error_id
))
);
}
}
return
RSVP
.
Queue
()
.
push
(
function
()
{
return
RSVP
.
all
(
tasks
);
})
.
push
(
function
()
{
g
.
element
.
insertBefore
(
errors_block
,
g
.
element
.
firstChild
);
})
.
push
(
g
.
notifyInvalid
.
bind
(
g
))
.
push
(
function
()
{
return
false
;
...
...
@@ -1631,8 +1660,14 @@
return
this
.
selfRemove
(
evt
);
}
var
button_list
=
this
.
props
.
add_buttons
,
var
link
=
evt
.
target
.
getAttribute
(
"
data-error-link
"
),
button_list
=
this
.
props
.
add_buttons
,
i
;
if
(
link
)
{
location
.
href
=
link
;
return
;
}
for
(
i
=
0
;
i
<
button_list
.
length
;
i
=
i
+
1
)
{
if
(
evt
.
target
===
button_list
[
i
].
element
)
{
return
button_list
[
i
].
event
(
evt
);
...
...
@@ -1663,4 +1698,4 @@
return
getFormValuesAsJSONDict
(
g
);
});
}(
window
,
document
,
rJS
,
RSVP
,
jIO
,
tv4
));
\ No newline at end of file
}(
window
,
document
,
location
,
rJS
,
RSVP
,
jIO
,
tv4
));
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
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 comment