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
186c60f4
Commit
186c60f4
authored
Oct 16, 2018
by
Boris Kocherov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
disable preset schema.default
parent
48b4dabe
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
34 additions
and
91 deletions
+34
-91
demo/gadget_demo_json_schema_form.js
demo/gadget_demo_json_schema_form.js
+5
-6
jsonform/gadget_json_generated_form_child.js
jsonform/gadget_json_generated_form_child.js
+24
-75
test/jsonform_test.js
test/jsonform_test.js
+0
-6
test/jsonform_test_view.js
test/jsonform_test_view.js
+5
-4
No files found.
demo/gadget_demo_json_schema_form.js
View file @
186c60f4
...
...
@@ -21,11 +21,12 @@
});
}
function
render_form
(
gadget
,
scope
,
schema
)
{
function
render_form
(
gadget
,
scope
,
schema
,
value
)
{
return
gadget
.
getDeclaredGadget
(
scope
)
.
push
(
function
(
g
)
{
return
g
.
render
({
schema
:
schema
schema
:
schema
,
value
:
value
});
});
}
...
...
@@ -42,9 +43,8 @@
function
render_document_selection_form
(
gadget
)
{
return
render_form
(
gadget
,
"
document
"
,
{
default
:
gadget
.
props
.
documents
[
0
],
enum
:
gadget
.
props
.
documents
});
}
,
gadget
.
props
.
documents
[
0
]
);
}
function
updateTextContent
(
g
)
{
...
...
@@ -107,9 +107,8 @@
return
RSVP
.
all
([
render_form
(
g
,
"
schema
"
,
{
type
:
"
string
"
,
default
:
g
.
props
.
schemas
[
0
],
enum
:
g
.
props
.
schemas
}),
}
,
g
.
props
.
schemas
[
0
]
),
render_document_selection_form
(
g
)
]);
});
...
...
jsonform/gadget_json_generated_form_child.js
View file @
186c60f4
...
...
@@ -121,7 +121,7 @@
return
schema
;
}
function
render_enum
(
g
,
schema
,
json_document
)
{
function
render_enum
(
schema
,
json_document
)
{
var
input
=
document
.
createElement
(
"
select
"
),
option
,
i
,
...
...
@@ -129,19 +129,12 @@
selected
=
false
,
enum_arr
=
schema
[
'
enum
'
];
input
.
size
=
1
;
if
(
schema
.
default
)
{
if
(
json_document
===
undefined
)
{
json_document
=
schema
.
default
;
g
.
props
.
changed
=
true
;
}
}
else
{
option
=
document
.
createElement
(
"
option
"
);
option
.
value
=
""
;
if
(
json_document
===
undefined
)
{
option
.
selected
=
true
;
}
input
.
appendChild
(
option
);
option
=
document
.
createElement
(
"
option
"
);
option
.
value
=
""
;
if
(
json_document
===
undefined
)
{
option
.
selected
=
true
;
}
input
.
appendChild
(
option
);
for
(
i
=
0
;
i
<
enum_arr
.
length
;
i
+=
1
)
{
if
(
enum_arr
.
hasOwnProperty
(
i
))
{
option
=
document
.
createElement
(
"
option
"
);
...
...
@@ -178,7 +171,7 @@
return
input
;
}
function
render_enum_with_title
(
g
,
schema_arr
,
json_document
,
selected_schema
)
{
function
render_enum_with_title
(
schema_arr
,
json_document
,
selected_schema
)
{
var
input
=
document
.
createElement
(
"
select
"
),
option
,
i
,
...
...
@@ -188,19 +181,12 @@
if
(
json_document
===
undefined
&&
selected_schema
!==
undefined
)
{
json_document
=
selected_schema
.
schema
.
const
;
}
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
);
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
...
...
@@ -237,7 +223,7 @@
return
input
;
}
function
render_boolean
(
g
,
schema
,
json_document
)
{
function
render_boolean
(
json_document
)
{
var
input
,
schema_for_selection
=
{
type
:
"
boolean
"
,
...
...
@@ -250,10 +236,7 @@
if
(
json_document
===
"
false
"
)
{
json_document
=
false
;
}
if
(
getDocumentType
(
schema
.
default
)
===
"
boolean
"
)
{
schema_for_selection
.
default
=
schema
.
default
;
}
input
=
render_enum
(
g
,
schema_for_selection
,
json_document
);
input
=
render_enum
(
schema_for_selection
,
json_document
);
input
.
setAttribute
(
'
data-json-type
'
,
"
boolean
"
);
return
input
;
}
...
...
@@ -698,29 +681,22 @@
var
input
,
is_items_arr
=
schema
.
items
instanceof
Array
,
minItems
=
schema
.
minItems
||
0
;
if
(
schema
.
default
===
undefined
&&
json_document
===
undefined
)
{
div_input
.
setAttribute
(
"
data-
undefined
"
,
"
true
"
);
if
(
json_document
instanceof
Array
&&
json_document
.
length
===
0
)
{
div_input
.
setAttribute
(
"
data-
json-empty-array
"
,
"
true
"
);
}
function
element_append
(
child
)
{
if
(
child
)
{
input
.
parentNode
.
insertBefore
(
child
,
input
);
div_input
.
removeAttribute
(
"
data-
undefined
"
);
div_input
.
removeAttribute
(
"
data-
json-empty-array
"
);
}
}
function
div_append
(
child
)
{
if
(
child
)
{
div_input
.
appendChild
(
child
);
div_input
.
removeAttribute
(
"
data-undefined
"
);
}
}
if
(
json_document
===
undefined
)
{
if
(
schema
.
hasOwnProperty
(
'
default
'
))
{
json_document
=
schema
.
default
;
gadget
.
props
.
changed
=
true
;
div_input
.
removeAttribute
(
"
data-json-empty-array
"
);
}
}
...
...
@@ -923,13 +899,13 @@
// render input begin
if
(
!
input
&&
schema_arr
[
0
].
is_arr_of_const
&&
schema_arr
.
length
>
1
)
{
input
=
render_enum_with_title
(
gadget
,
schema_arr
,
json_document
,
options
.
selected_schema
);
input
=
render_enum_with_title
(
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
(
gadget
,
schema
,
json_document
);
input
=
render_enum
(
schema
,
json_document
);
// XXX take in account existing type with enum
type_changed
=
false
;
}
...
...
@@ -939,7 +915,7 @@
}
if
(
!
input
&&
type
===
"
boolean
"
)
{
input
=
render_boolean
(
gadget
,
schema
,
json_document
);
input
=
render_boolean
(
json_document
);
}
if
(
!
input
&&
[
"
string
"
,
"
integer
"
,
"
number
"
,
"
null
"
].
indexOf
(
type
)
>=
0
)
{
...
...
@@ -956,10 +932,6 @@
}
if
(
type
===
"
integer
"
||
type
===
"
number
"
)
{
if
(
json_document
===
undefined
&&
typeof
schema
.
default
===
"
number
"
)
{
input
.
value
=
schema
.
default
;
gadget
.
props
.
changed
=
true
;
}
input
.
setAttribute
(
"
data-json-type
"
,
type
);
if
(
json_document
===
undefined
||
json_document
===
null
||
typeof
json_document
===
"
number
"
)
{
...
...
@@ -991,10 +963,6 @@
input
.
max
=
schema
.
maximum
;
}
}
else
{
if
(
json_document
===
undefined
&&
typeof
schema
.
default
===
"
string
"
)
{
input
.
value
=
schema
.
default
;
gadget
.
props
.
changed
=
true
;
}
input
.
type
=
"
text
"
;
if
(
schema
.
pattern
)
{
input
.
pattern
=
schema
.
pattern
;
...
...
@@ -1012,10 +980,6 @@
}
}
}
if
(
schema
.
default
!==
undefined
)
{
input
.
setAttribute
(
'
data-default-value
'
,
JSON
.
stringify
(
schema
.
default
));
input
.
placeholder
=
schema
.
default
;
}
}
// render input end
...
...
@@ -1326,18 +1290,8 @@
root
.
appendChild
(
child
);
}
if
(
JSON
.
stringify
(
schema
.
default
)
===
'
{}
'
)
{
// save default value as attribute only for empty values
root
.
parentElement
.
setAttribute
(
"
data-default-value
"
,
'
{}
'
);
}
if
(
json_document
===
undefined
)
{
if
(
schema
.
hasOwnProperty
(
'
default
'
))
{
json_document
=
schema
.
default
;
g
.
props
.
changed
=
true
;
}
else
{
json_document
=
{};
}
json_document
=
{};
}
return
expandProperties
(
g
,
schema
.
properties
,
schema_path
+
'
/properties/
'
,
required
)
...
...
@@ -1601,9 +1555,6 @@
g
.
element
.
getAttribute
(
"
data-gadget-scope
"
)
+
"
']
"
);
for
(
i
=
0
;
i
<
array
.
length
;
i
+=
1
)
{
path
=
array
[
i
].
getAttribute
(
"
data-json-path
"
).
slice
(
0
,
-
1
);
if
(
array
[
i
].
getAttribute
(
"
data-default-value
"
)
===
"
{}
"
)
{
convertOnMultiLevel
(
multi_level_dict
,
path
,
{});
}
}
for
(
path
in
options
.
arrays
)
{
...
...
@@ -1612,7 +1563,7 @@
.
querySelectorAll
(
"
div[data-gadget-parent-scope='
"
+
g
.
element
.
getAttribute
(
"
data-gadget-scope
"
)
+
"
']
"
);
len
=
array
.
length
;
if
(
len
===
0
&&
!
options
.
arrays
[
path
].
hasAttribute
(
'
data-undefined
'
))
{
options
.
arrays
[
path
].
hasAttribute
(
'
data-json-empty-array
'
))
{
convertOnMultiLevel
(
multi_level_dict
,
path
.
slice
(
0
,
-
1
),
[]);
}
for
(
i
=
0
;
i
<
len
;
i
=
i
+
1
)
{
...
...
@@ -1670,8 +1621,6 @@
}
else
{
json_dict
[
input
.
name
]
=
input
.
value
;
}
}
else
if
(
input
.
hasAttribute
(
'
data-default-value
'
))
{
json_dict
[
input
.
name
]
=
JSON
.
parse
(
input
.
getAttribute
(
'
data-default-value
'
));
}
}
});
...
...
test/jsonform_test.js
View file @
186c60f4
...
...
@@ -134,12 +134,6 @@
"
allOf with base schema: mismatch second allOf
"
:
{
invert_valid
:
true
,
changed
:
true
},
// schema.default used for field if field undefined so json_document changed after
// render() and valid status inverted
"
invalid string value for default: still valid when the invalid default is used
"
:
{
invert_valid
:
true
,
changed
:
true
}
};
...
...
test/jsonform_test_view.js
View file @
186c60f4
...
...
@@ -26,11 +26,12 @@
});
}
function
render_form
(
gadget
,
scope
,
schema
)
{
function
render_form
(
gadget
,
scope
,
schema
,
value
)
{
return
gadget
.
getDeclaredGadget
(
scope
)
.
push
(
function
(
g
)
{
return
g
.
render
({
schema
:
schema
schema
:
schema
,
value
:
value
});
});
}
...
...
@@ -101,6 +102,7 @@
m
,
schema
,
t
;
g
.
props
.
schemas
.
push
(
""
);
for
(
i
=
0
;
i
<
list
.
length
;
i
+=
1
)
{
for
(
k
=
0
;
k
<
list
[
i
].
length
;
k
+=
1
)
{
m
=
list
[
i
][
k
];
...
...
@@ -131,9 +133,8 @@
return
RSVP
.
all
([
render_form
(
g
,
"
schema
"
,
{
type
:
"
string
"
,
default
:
g
.
props
.
schemas
[
0
],
enum
:
g
.
props
.
schemas
})
}
,
g
.
props
.
schemas
[
0
]
)
]);
});
})
...
...
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