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
Boris Kocherov
rjs_json_form
Commits
76541c25
Commit
76541c25
authored
Feb 28, 2019
by
Boris Kocherov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
partial add ignore_incorrect option.
currently realized only for enum and object
parent
ee725769
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
61 additions
and
38 deletions
+61
-38
jsonform.gadget.js
jsonform.gadget.js
+2
-1
jsonform/gadget_json_generated_form_child.js
jsonform/gadget_json_generated_form_child.js
+59
-37
No files found.
jsonform.gadget.js
View file @
76541c25
...
...
@@ -995,7 +995,8 @@
.
push
(
function
(
value
)
{
return
gadget
.
rerender
({
schema
:
opt
.
schema
,
value
:
value
value
:
value
,
ignore_incorrect
:
opt
.
ignore_incorrect
})
.
push
(
function
()
{
return
gadget
.
reValidate
(
value
,
opt
.
schema
);
...
...
jsonform/gadget_json_generated_form_child.js
View file @
76541c25
...
...
@@ -125,20 +125,21 @@
return
schema
;
}
function
render_enum
(
schema
,
json_document
)
{
function
render_enum
(
g
,
schema
,
json_document
)
{
var
input
=
document
.
createElement
(
"
select
"
),
option
,
i
,
ser_value
,
selected
=
false
,
empty_option
,
enum_arr
=
schema
[
'
enum
'
];
input
.
size
=
1
;
option
=
document
.
createElement
(
"
option
"
);
option
.
value
=
""
;
empty_
option
=
document
.
createElement
(
"
option
"
);
empty_
option
.
value
=
""
;
if
(
json_document
===
undefined
)
{
option
.
selected
=
true
;
empty_
option
.
selected
=
true
;
}
input
.
appendChild
(
option
);
input
.
appendChild
(
empty_
option
);
for
(
i
=
0
;
i
<
enum_arr
.
length
;
i
+=
1
)
{
option
=
document
.
createElement
(
"
option
"
);
ser_value
=
JSON
.
stringify
(
enum_arr
[
i
]);
...
...
@@ -155,25 +156,31 @@
input
.
appendChild
(
option
);
}
if
(
json_document
!==
undefined
&&
!
selected
)
{
// save original json_document even if it
// not support with schema
// XXX element should be removed on first user interact
option
=
document
.
createElement
(
"
option
"
);
ser_value
=
JSON
.
stringify
(
json_document
);
option
.
value
=
ser_value
;
if
(
typeof
json_document
===
"
string
"
)
{
option
.
textContent
=
json_document
;
if
(
g
.
props
.
ignore_incorrect
)
{
empty_option
.
selected
=
true
;
g
.
props
.
changed
=
true
;
}
else
{
option
.
textContent
=
ser_value
;
// save original json_document even if it
// not support with schema
// XXX element should be removed on first user interact
option
=
document
.
createElement
(
"
option
"
);
ser_value
=
JSON
.
stringify
(
json_document
);
option
.
value
=
ser_value
;
if
(
typeof
json_document
===
"
string
"
)
{
option
.
textContent
=
json_document
;
}
else
{
option
.
textContent
=
ser_value
;
}
option
.
selected
=
true
;
input
.
appendChild
(
option
);
}
option
.
selected
=
true
;
input
.
appendChild
(
option
);
}
return
input
;
}
function
render_enum_with_title
(
schema_arr
,
json_document
,
selected_schema
)
{
function
render_enum_with_title
(
g
,
schema_arr
,
json_document
,
selected_schema
)
{
var
input
=
document
.
createElement
(
"
select
"
),
empty_option
,
option
,
i
,
ser_value
,
...
...
@@ -182,12 +189,12 @@
if
(
json_document
===
undefined
&&
selected_schema
!==
undefined
)
{
json_document
=
selected_schema
.
schema
.
const
;
}
option
=
document
.
createElement
(
"
option
"
);
option
.
value
=
""
;
empty_
option
=
document
.
createElement
(
"
option
"
);
empty_
option
.
value
=
""
;
if
(
json_document
===
undefined
)
{
option
.
selected
=
true
;
empty_
option
.
selected
=
true
;
}
input
.
appendChild
(
option
);
input
.
appendChild
(
empty_
option
);
for
(
i
=
0
;
i
<
schema_arr
.
length
;
i
+=
1
)
{
option
=
document
.
createElement
(
"
option
"
);
// XXX use number id for speedup
...
...
@@ -207,24 +214,29 @@
input
.
appendChild
(
option
);
}
if
(
json_document
!==
undefined
&&
!
selected
)
{
// save original json_document even if it
// not support with schema
// XXX element should be removed on first user interact
option
=
document
.
createElement
(
"
option
"
);
ser_value
=
JSON
.
stringify
(
json_document
);
option
.
value
=
ser_value
;
if
(
typeof
json_document
===
"
string
"
)
{
option
.
textContent
=
json_document
;
if
(
g
.
props
.
ignore_incorrect
)
{
empty_option
.
selected
=
true
;
g
.
props
.
changed
=
true
;
}
else
{
option
.
textContent
=
ser_value
;
// save original json_document even if it
// not support with schema
// XXX element should be removed on first user interact
option
=
document
.
createElement
(
"
option
"
);
ser_value
=
JSON
.
stringify
(
json_document
);
option
.
value
=
ser_value
;
if
(
typeof
json_document
===
"
string
"
)
{
option
.
textContent
=
json_document
;
}
else
{
option
.
textContent
=
ser_value
;
}
option
.
selected
=
true
;
input
.
appendChild
(
option
);
}
option
.
selected
=
true
;
input
.
appendChild
(
option
);
}
return
input
;
}
function
render_boolean
(
json_document
)
{
function
render_boolean
(
g
,
json_document
)
{
var
input
,
schema_for_selection
=
{
type
:
"
boolean
"
,
...
...
@@ -237,7 +249,7 @@
if
(
json_document
===
"
false
"
)
{
json_document
=
false
;
}
input
=
render_enum
(
schema_for_selection
,
json_document
);
input
=
render_enum
(
g
,
schema_for_selection
,
json_document
);
input
.
setAttribute
(
'
data-json-type
'
,
"
boolean
"
);
return
input
;
}
...
...
@@ -333,6 +345,7 @@
document
:
options
.
json_document
,
display_label
:
options
.
parent_type
!==
"
array
"
,
saveOrigValue
:
g
.
props
.
saveOrigValue
,
ignore_incorrect
:
g
.
props
.
ignore_incorrect
,
scope
:
scope
})
.
push
(
function
()
{
...
...
@@ -994,13 +1007,13 @@
// render input begin
if
(
!
input
&&
schema_arr
[
0
].
is_arr_of_const
&&
schema_arr
.
length
>
1
)
{
input
=
render_enum_with_title
(
schema_arr
,
json_document
,
options
.
selected_schema
);
input
=
render_enum_with_title
(
gadget
,
schema_arr
,
json_document
,
options
.
selected_schema
);
}
if
(
!
input
&&
schema
.
const
!==
undefined
)
{
input
=
render_const
(
gadget
,
schema
,
json_document
);
}
if
(
!
input
&&
schema
.
enum
!==
undefined
)
{
input
=
render_enum
(
schema
,
json_document
);
input
=
render_enum
(
gadget
,
schema
,
json_document
);
// XXX take in account existing type with enum
type_changed
=
false
;
}
...
...
@@ -1010,7 +1023,7 @@
}
if
(
!
input
&&
type
===
"
boolean
"
)
{
input
=
render_boolean
(
json_document
);
input
=
render_boolean
(
gadget
,
json_document
);
}
if
(
!
input
&&
[
"
string
"
,
"
integer
"
,
"
number
"
,
"
null
"
].
indexOf
(
type
)
>=
0
)
{
...
...
@@ -1560,6 +1573,10 @@
return
queue
;
})
.
push
(
function
()
{
if
(
g
.
props
.
ignore_incorrect
)
{
g
.
props
.
changed
=
true
;
return
;
}
var
key
,
queue
=
RSVP
.
Queue
();
for
(
key
in
json_document
)
{
...
...
@@ -2058,6 +2075,8 @@
}
g
.
props
.
property_name
=
property_name
;
g
.
props
.
schema_arr
=
options
.
schema_arr
;
// XXX realized only for enum and object
g
.
props
.
ignore_incorrect
=
options
.
ignore_incorrect
;
g
.
props
.
render_opt
=
{
type
:
options
.
type
,
selected_schema
:
options
.
selected_schema
,
...
...
@@ -2072,6 +2091,9 @@
var
g
=
this
,
for_delete
,
root
=
g
.
element
.
querySelector
(
'
[data-json-path="/"]
'
);
if
(
opt
.
ignore_incorrect
!==
undefined
)
{
g
.
props
.
ignore_incorrect
=
opt
.
ignore_incorrect
;
}
g
.
props
.
changed
=
false
;
g
.
props
.
inputs
=
[];
g
.
props
.
add_buttons
=
[];
...
...
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