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
424b799e
Commit
424b799e
authored
Apr 25, 2018
by
Boris Kocherov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
render_array() use schema.minItems for display all required items
parent
da8c0b3d
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
65 additions
and
34 deletions
+65
-34
gadget_json_generated_form.js
gadget_json_generated_form.js
+65
-34
No files found.
gadget_json_generated_form.js
View file @
424b799e
...
...
@@ -374,6 +374,17 @@
});
}
function
checkSchemaArrOneChoise
(
schema_arr
)
{
if
(
schema_arr
.
length
===
1
)
{
if
(
schema_arr
[
0
].
type
instanceof
Array
)
{
return
schema_arr
[
0
].
type
.
length
<=
1
;
}
else
{
return
true
;
}
}
return
false
;
}
function
convertExpandedProperties2array
(
properties
)
{
var
property_name
,
arr
=
[],
...
...
@@ -628,13 +639,9 @@
}
function
render_array
(
gadget
,
schema
,
json_document
,
root
,
path
,
schema_path
)
{
var
queue
=
RSVP
.
Queue
(),
div
,
var
div
,
div_input
,
input
,
item_schema
,
i
,
maxItems
=
schema
.
maxItems
;
input
;
div
=
document
.
createElement
(
"
div
"
);
div
.
setAttribute
(
"
class
"
,
"
subfield
"
);
div
.
title
=
schema
.
description
;
...
...
@@ -648,13 +655,55 @@
}
}
item_schema
=
schema
.
items
;
function
div_append
(
child
)
{
if
(
child
)
{
div_input
.
appendChild
(
child
);
}
}
// XXX add failback rendering if json_document not array
// input = render_textarea(schema, default_value, "array");
return
expandSchema
(
gadget
,
schema
.
items
,
schema_path
+
'
/items
'
)
.
push
(
function
(
schema_arr
)
{
var
queue
=
RSVP
.
Queue
(),
i
,
minItems
=
schema
.
minItems
||
0
,
len
=
0
;
// XXX rewrite loading document for anyOf schema
if
(
json_document
)
{
for
(
i
=
0
;
i
<
json_document
.
length
;
i
=
i
+
1
)
{
queue
.
push
(
function
()
{
return
expandSchema
(
gadget
,
item_schema
,
schema_path
+
'
/items
'
);
.
push
(
addSubForm
.
bind
(
gadget
,
{
gadget
:
gadget
,
parent_type
:
'
array
'
,
schema_path
:
schema_path
+
'
/items
'
,
schema_part
:
schema_arr
,
default_dict
:
json_document
[
i
]
})
.
push
(
function
(
schema_arr
)
{
return
render_schema_selector
(
gadget
,
"
add item to array
"
,
)
.
push
(
div_append
);
}
len
=
json_document
.
length
;
}
if
(
checkSchemaArrOneChoise
(
schema_arr
)
&&
minItems
>
len
)
{
for
(
i
=
0
;
i
<
(
minItems
-
len
);
i
+=
1
)
{
queue
.
push
(
addSubForm
.
bind
(
gadget
,
{
gadget
:
gadget
,
parent_type
:
'
array
'
,
schema_path
:
schema_arr
[
0
].
schema_path
,
schema_part
:
schema_arr
[
0
].
schema
})
)
.
push
(
div_append
);
}
}
queue
.
push
(
render_schema_selector
.
bind
(
gadget
,
gadget
,
"
add item to array
"
,
schema_arr
,
function
(
value
)
{
return
addSubForm
({
gadget
:
gadget
,
...
...
@@ -664,36 +713,18 @@
schema_part
:
value
.
schema
})
.
push
(
element_append
);
});
}));
return
queue
;
})
.
push
(
function
(
element
)
{
// var maxItems = schema.maxItems;
input
=
element
;
// XXX update on every add/delete item
input
.
hidden
=
maxItems
!==
undefined
&&
json_document
.
length
>=
maxItems
;
//
input.hidden = maxItems !== undefined && json_document.length >= maxItems;
div_input
.
appendChild
(
input
);
div
.
appendChild
(
div_input
);
root
.
appendChild
(
div
);
});
// XXX rewrite loading document for anyOf schema
if
(
json_document
)
{
for
(
i
=
0
;
i
<
json_document
.
length
;
i
=
i
+
1
)
{
queue
.
push
(
addSubForm
.
bind
(
gadget
,
{
gadget
:
gadget
,
parent_type
:
'
array
'
,
schema_path
:
schema_path
+
'
/items
'
,
schema_part
:
item_schema
,
default_dict
:
json_document
[
i
]
})
)
.
push
(
element_append
);
}
}
// XXX add failback rendering if json_document not array
// input = render_textarea(schema, default_value, "array");
return
queue
;
}
function
render_field
(
gadget
,
key
,
path
,
json_field
,
default_value
,
root
,
schema_path
,
options
)
{
...
...
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