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
e3d91b30
Commit
e3d91b30
authored
Aug 07, 2018
by
Boris Kocherov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use html attribute data-origin-value for save original value parts of document
i need it for workaround `data side errors` in tests
parent
8116ef49
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
49 additions
and
29 deletions
+49
-29
jsonform/gadget_json_generated_form_child.js
jsonform/gadget_json_generated_form_child.js
+49
-29
No files found.
jsonform/gadget_json_generated_form_child.js
View file @
e3d91b30
...
...
@@ -617,6 +617,7 @@
error_message
,
input
,
first_path
,
type_changed
,
queue
=
RSVP
.
Queue
();
if
(
json_field
instanceof
Array
)
{
...
...
@@ -645,15 +646,11 @@
type
=
getDocumentType
(
default_value
);
}
// XXX bad peace of code
// i do not sure that type can be computed so
// but our schema in slapos bad
if
(
!
type
)
{
if
(
json_field
.
properties
&&
json_field
.
required
&&
json_field
.
required
.
length
>
0
)
{
type
=
"
object
"
;
}
if
(
typeof
type
===
"
string
"
)
{
// it's only for simple types so we not use
// complex type detection
type_changed
=
default_value
!==
undefined
&&
typeof
default_value
!==
type
;
}
div
=
document
.
createElement
(
"
div
"
);
...
...
@@ -708,6 +705,8 @@
if
(
json_field
.
enum
!==
undefined
)
{
input
=
render_enum
(
json_field
,
default_value
);
// XXX take in account existing type with enum
type_changed
=
false
;
}
if
(
type
===
"
boolean
"
)
{
...
...
@@ -721,10 +720,11 @@
input
=
document
.
createElement
(
"
input
"
);
if
(
default_value
!==
undefined
)
{
if
(
typeof
default_value
===
"
object
"
)
{
default_
value
=
JSON
.
stringify
(
default_value
);
}
input
.
value
=
JSON
.
stringify
(
default_value
);
}
else
{
input
.
value
=
default_value
;
}
}
if
(
type
===
"
integer
"
||
type
===
"
number
"
)
{
if
(
default_value
===
undefined
&&
typeof
json_field
.
default
===
"
number
"
)
{
...
...
@@ -732,8 +732,16 @@
}
input
.
type
=
"
number
"
;
input
.
setAttribute
(
"
data-json-type
"
,
type
);
type_changed
=
default_value
!==
undefined
&&
typeof
default_value
!==
"
number
"
;
if
(
type
===
"
integer
"
)
{
input
.
setAttribute
(
"
step
"
,
"
1
"
);
if
(
default_value
!==
undefined
&&
parseInt
(
default_value
,
10
)
!==
default_value
)
{
// original json_document contain float schema
// limit integer we can save original document
type_changed
=
true
;
}
}
if
(
type
===
"
number
"
)
{
input
.
setAttribute
(
"
step
"
,
"
any
"
);
...
...
@@ -786,6 +794,9 @@
gadget
.
props
.
inputs
.
push
(
input
);
input
.
name
=
first_path
;
input
.
required
=
options
.
required
;
if
(
type_changed
)
{
input
.
setAttribute
(
'
data-origin-value
'
,
JSON
.
stringify
(
default_value
));
}
// XXX for gui
//input.setAttribute("class", "slapos-parameter");
div_input
.
appendChild
(
input
);
...
...
@@ -1291,6 +1302,9 @@
var
json_dict
=
{},
k
;
g
.
props
.
inputs
.
forEach
(
function
(
input
)
{
if
(
input
.
hasAttribute
(
'
data-origin-value
'
))
{
json_dict
[
input
.
name
]
=
JSON
.
parse
(
input
.
getAttribute
(
'
data-origin-value
'
));
}
else
{
if
(
input
.
required
||
input
.
value
!==
""
)
{
var
type
=
input
.
getAttribute
(
'
data-json-type
'
);
if
(
type
===
'
number
'
)
{
...
...
@@ -1313,6 +1327,7 @@
json_dict
[
input
.
name
]
=
input
.
value
;
}
}
}
});
for
(
k
in
json_dict
)
{
if
(
json_dict
.
hasOwnProperty
(
k
))
{
...
...
@@ -1578,10 +1593,15 @@
var
gadget
=
this
,
field_list
=
this
.
props
.
inputs
,
i
,
input
,
changed
=
false
;
// on form data field
for
(
i
=
0
;
i
<
field_list
.
length
;
i
=
i
+
1
)
{
if
(
evt
.
target
===
field_list
[
i
])
{
input
=
evt
.
target
;
if
(
input
.
hasAttribute
(
'
data-origin-value
'
))
{
input
.
removeAttribute
(
'
data-origin-value
'
);
}
changed
=
true
;
}
}
...
...
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