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
Jérome Perrin
rjs_json_form
Commits
077403f5
Commit
077403f5
authored
Sep 19, 2018
by
Boris Kocherov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add render_enum_with_title()
parent
eca3154f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
83 additions
and
16 deletions
+83
-16
jsonform.gadget.js
jsonform.gadget.js
+17
-14
jsonform/gadget_json_generated_form_child.js
jsonform/gadget_json_generated_form_child.js
+66
-2
No files found.
jsonform.gadget.js
View file @
077403f5
...
...
@@ -583,6 +583,20 @@
}];
});
};
function
schema_arr_marker
(
schema_arr
)
{
var
i
;
for
(
i
=
0
;
i
<
schema_arr
.
length
;
i
+=
1
)
{
if
(
!
schema_arr
[
i
].
schema
.
hasOwnProperty
(
'
const
'
))
{
schema_arr
[
0
].
is_arr_of_const
=
false
;
break
;
}
if
(
i
===
schema_arr
.
length
-
1
)
{
schema_arr
[
0
].
is_arr_of_const
=
true
;
}
}
return
schema_arr
;
}
function
expandSchemaForField
(
g
,
schema
,
schema_path
,
for_required
)
{
var
required_stack
,
...
...
@@ -595,19 +609,7 @@
}
g
.
props
.
schema_required_urls
[
schema_path
]
=
required_stack
;
return
expandSchema
(
g
,
schema
,
schema_path
)
.
push
(
function
(
schema_arr
)
{
var
i
;
for
(
i
=
0
;
i
<
schema_arr
.
length
;
i
+=
1
)
{
if
(
!
schema_arr
[
i
].
schema
.
hasOwnProperty
(
'
const
'
))
{
schema_arr
[
0
].
is_arr_of_const
=
false
;
break
;
}
if
(
i
===
schema_arr
.
length
-
1
)
{
schema_arr
[
0
].
is_arr_of_const
=
true
;
}
}
return
schema_arr
;
});
.
push
(
schema_arr_marker
);
}
rJS
(
window
)
...
...
@@ -821,7 +823,8 @@
schema_url
=
g
.
state
.
schema_url
||
(
json_document
&&
json_document
.
$schema
);
if
(
schema_url
)
{
queue
=
loadJSONSchema
(
g
,
schema_url
);
queue
=
loadJSONSchema
(
g
,
schema_url
)
.
push
(
schema_arr_marker
);
}
}
if
(
queue
)
{
...
...
jsonform/gadget_json_generated_form_child.js
View file @
077403f5
...
...
@@ -178,6 +178,62 @@
return
input
;
}
function
render_enum_with_title
(
g
,
schema_arr
,
json_document
)
{
var
input
=
document
.
createElement
(
"
select
"
),
option
,
i
,
ser_value
,
selected
=
false
;
input
.
size
=
1
;
if
(
schema_arr
[
0
].
schema
.
default
)
{
if
(
json_document
===
undefined
)
{
json_document
=
schema_arr
[
0
].
schema
.
default
;
g
.
props
.
changed
=
true
;
}
}
else
{
option
=
document
.
createElement
(
"
option
"
);
option
.
value
=
""
;
if
(
json_document
===
undefined
)
{
option
.
selected
=
true
;
}
input
.
appendChild
(
option
);
}
for
(
i
=
0
;
i
<
schema_arr
.
length
;
i
+=
1
)
{
option
=
document
.
createElement
(
"
option
"
);
// XXX use number id for speedup
ser_value
=
JSON
.
stringify
(
schema_arr
[
i
].
schema
.
const
);
option
.
value
=
ser_value
;
if
(
schema_arr
[
i
].
schema
.
title
)
{
option
.
textContent
=
schema_arr
[
i
].
schema
.
title
;
}
else
if
(
typeof
schema_arr
[
i
].
schema
.
const
===
"
string
"
)
{
option
.
textContent
=
schema_arr
[
i
].
schema
.
const
;
}
else
{
option
.
textContent
=
ser_value
;
}
if
(
deepEqual
(
schema_arr
[
i
].
schema
.
const
,
json_document
))
{
option
.
selected
=
true
;
selected
=
true
;
}
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
;
}
else
{
option
.
textContent
=
ser_value
;
}
option
.
selected
=
true
;
input
.
appendChild
(
option
);
}
return
input
;
}
function
render_boolean
(
g
,
schema
,
json_document
)
{
var
input
,
schema_for_selection
=
{
...
...
@@ -890,9 +946,15 @@
div_input
.
setAttribute
(
"
id
"
,
gadget
.
element
.
getAttribute
(
"
data-gadget-scope
"
)
+
first_path
+
'
/
'
);
div_input
.
setAttribute
(
"
class
"
,
"
input
"
);
if
(
schema
.
const
!==
undefined
)
{
// render input begin
if
(
!
input
&&
schema_arr
[
0
].
is_arr_of_const
)
{
input
=
render_enum_with_title
(
gadget
,
schema_arr
,
json_document
);
}
if
(
!
input
&&
schema
.
const
!==
undefined
)
{
input
=
render_const
(
gadget
,
schema
,
json_document
);
}
else
if
(
schema
.
enum
!==
undefined
)
{
}
if
(
!
input
&&
schema
.
enum
!==
undefined
)
{
input
=
render_enum
(
gadget
,
schema
,
json_document
);
// XXX take in account existing type with enum
type_changed
=
false
;
...
...
@@ -1020,6 +1082,8 @@
div
.
setAttribute
(
"
data-json-type
"
,
type
);
}
// render input end
if
(
schema
.
info
!==
undefined
)
{
span_info
=
document
.
createElement
(
"
span
"
);
span_info
.
textContent
=
schema
.
info
;
...
...
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