Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
erp5
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
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Léo-Paul Géneau
erp5
Commits
244fb9fa
Commit
244fb9fa
authored
Apr 15, 2024
by
Rafael Monnerat
Browse files
Options
Browse Files
Download
Plain Diff
json_editor: Implement field/form validation and other fixes
See merge request
nexedi/erp5!1918
parents
0556a362
b7620d48
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
86 additions
and
6 deletions
+86
-6
bt5/erp5_json_editor/SkinTemplateItem/portal_skins/erp5_json_editor/json-editor.gadget.js.js
...em/portal_skins/erp5_json_editor/json-editor.gadget.js.js
+86
-6
No files found.
bt5/erp5_json_editor/SkinTemplateItem/portal_skins/erp5_json_editor/json-editor.gadget.js.js
View file @
244fb9fa
...
@@ -156,6 +156,87 @@
...
@@ -156,6 +156,87 @@
return
value
.
toString
();
return
value
.
toString
();
};
};
JSONEditor
.
defaults
.
editors
.
multiple
.
prototype
.
setValue
=
function
(
val
,
initial
)
{
/* Determine type by getting the first one that validates */
var
field
=
this
,
typeChanged
,
prevType
=
this
.
type
,
/* find the best match one */
fitTestVal
=
{
match
:
0
,
extra
:
0
,
i
:
this
.
type
},
validVal
=
{
match
:
0
,
extra
:
null
,
i
:
null
},
finalI
;
field
.
validators
.
forEach
(
function
(
validator
,
i
)
{
var
fitTestResult
=
null
;
if
(
field
.
anyOf
!==
undefined
&&
field
.
anyOf
)
{
/* here is tries to guess what fits best, but it is
expected that some sense of similarity between the forms
*/
fitTestResult
=
validator
.
fitTest
(
val
);
if
(
fitTestVal
.
match
<
fitTestResult
.
match
)
{
fitTestVal
=
fitTestResult
;
fitTestVal
.
i
=
i
;
}
else
if
(
fitTestVal
.
match
===
fitTestResult
.
match
)
{
if
(
fitTestVal
.
extra
>
fitTestResult
.
extra
)
{
fitTestVal
=
fitTestResult
;
fitTestVal
.
i
=
i
;
}
}
}
if
(
!
validator
.
validate
(
val
).
length
&&
validVal
.
i
===
null
)
{
validVal
.
i
=
i
;
if
(
fitTestResult
!==
null
)
{
validVal
.
match
=
fitTestResult
.
match
;
}
}
else
{
fitTestVal
=
validVal
;
}
});
finalI
=
validVal
.
i
;
/* if the best fit schema has more match properties, then use the best fit schema. */
/* usually the value could be */
if
(
field
.
anyOf
!==
undefined
&&
field
.
anyOf
)
{
if
(
validVal
.
match
<
fitTestVal
.
match
)
{
finalI
=
fitTestVal
.
i
;
}
}
if
(
field
.
if
)
{
finalI
=
field
.
getIfType
(
val
);
}
if
(
finalI
===
null
)
{
if
(
isEmpty
(
val
))
{
finalI
=
field
.
type
;
}
else
{
throw
new
Error
(
"
Could not safely render data into the form.
"
)
}
}
field
.
type
=
finalI
;
field
.
switcher
.
value
=
field
.
display_text
[
finalI
];
typeChanged
=
field
.
type
!==
prevType
;
if
(
typeChanged
)
{
field
.
switchEditor
(
field
.
type
);
field
.
editors
[
field
.
type
].
setValue
(
val
,
initial
);
}
if
((
val
!==
undefined
)
&&
(
!
isEmpty
(
val
)))
{
field
.
editors
[
field
.
type
].
setValue
(
val
,
initial
);
}
field
.
refreshValue
();
field
.
onChange
(
typeChanged
);
};
if
(
JSONEditor
.
defaults
.
editors
.
object
.
prototype
.
original_getPropertySchema
===
undefined
)
{
if
(
JSONEditor
.
defaults
.
editors
.
object
.
prototype
.
original_getPropertySchema
===
undefined
)
{
JSONEditor
.
defaults
.
editors
.
object
.
prototype
.
original_getPropertySchema
=
JSONEditor
.
defaults
.
editors
.
object
.
prototype
.
getPropertySchema
;
JSONEditor
.
defaults
.
editors
.
object
.
prototype
.
original_getPropertySchema
=
JSONEditor
.
defaults
.
editors
.
object
.
prototype
.
getPropertySchema
;
}
}
...
@@ -178,8 +259,7 @@
...
@@ -178,8 +259,7 @@
}
}
}
}
return
schema
;
return
schema
;
}
};
/* The original code would remove the field if value is undefined */
/* The original code would remove the field if value is undefined */
JSONEditor
.
defaults
.
editors
.
object
.
prototype
.
setValue
=
function
(
value
,
initial
)
{
JSONEditor
.
defaults
.
editors
.
object
.
prototype
.
setValue
=
function
(
value
,
initial
)
{
...
@@ -312,7 +392,7 @@
...
@@ -312,7 +392,7 @@
disable_array_delete_last_row
:
true
,
disable_array_delete_last_row
:
true
,
no_additional_properties
:
false
,
no_additional_properties
:
false
,
remove_empty_properties
:
true
,
remove_empty_properties
:
true
,
keep_oneof_values
:
fals
e
,
keep_oneof_values
:
tru
e
,
startval
:
JSON
.
parse
(
gadget
.
state
.
value
),
startval
:
JSON
.
parse
(
gadget
.
state
.
value
),
readonly
:
gadget
.
state
.
editable
?
false
:
true
readonly
:
gadget
.
state
.
editable
?
false
:
true
});
});
...
@@ -343,9 +423,9 @@
...
@@ -343,9 +423,9 @@
return
form_data
;
return
form_data
;
})
})
.
declareMethod
(
'
checkValidity
'
,
function
()
{
.
declareMethod
(
'
checkValidity
'
,
function
()
{
if
(
this
.
state
.
errors
!
==
undefined
)
{
if
(
this
.
editor
=
==
undefined
)
{
return
t
his
.
state
.
errors
.
length
===
0
;
return
t
rue
;
}
}
return
true
;
return
isEmpty
(
this
.
editor
.
validate
())
;
});
});
}(
window
,
rJS
,
RSVP
,
JSONEditor
,
domsugar
,
JSON
,
$RefParser
,
URL
));
}(
window
,
rJS
,
RSVP
,
JSONEditor
,
domsugar
,
JSON
,
$RefParser
,
URL
));
\ No newline at end of file
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