Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
D
docs-phd5
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
dmstr
docs-phd5
Commits
a534c49f
Commit
a534c49f
authored
Jul 21, 2017
by
g.bisurgi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
updated json-editpr-customization tutorial
parent
e998c831
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
35 additions
and
12 deletions
+35
-12
json-editor-customizations.md
guide/tutorials/json-editor-customizations.md
+35
-12
No files found.
guide/tutorials/json-editor-customizations.md
View file @
a534c49f
# custom editor
# Custom editor
First of all when we use the word "editor" in the JSONEditor world we are
actually saying "input". Every input in the generated form is an editor. So an
editor can be a textarea, a checkbox, a bunch of radio buttons, etc.
JSONEditor comes with built in editors but we can "build" our custom editor
to. In order to build an editor we have to "extend" (javascript does not have
inheritance) the built in "JSONEditor.AbstractEditor" class. and add it to the
`JSONEditor.defaults.editors`
object.
In example a date picker editor that needs (as a dependency) the jquery datepicker.
...
...
@@ -99,7 +108,8 @@ In example a date picker editor that needs (as a dependency) the jquery datepick
# Add the editor resolver
In order to use a custom editor you have to register it, like this
In order to
**USE**
a custom editor you have to
**REGISTER**
it adding a "resolver" into
the
`JSONEditor.defaults.resolvers`
object, like this:
JSONEditor.defaults.resolvers.unshift(function(schema) {
if(schema.format === 'datepicker') {
...
...
@@ -109,7 +119,7 @@ In order to use a custom editor you have to register it, like this
after registration you can add something like this in your schema
"Datum": {
"Datum": {
"title": 'Date',
"type": "string",
"format": "datepicker",
...
...
@@ -120,17 +130,13 @@ after registration you can add something like this in your schema
"dayNamesMin": [ "So", "Mo", "Di", "Mi", "Do", "Fr", "Sa" ],
"hideIfNoPrevNext": true,
"firstDay": 1
},
"propertyOrder": 1,
"required": true,
"options": {
"grid_columns": 3
}
}
}
#
c
ustom validator
#
C
ustom validator
In example a custo validator that will be applied to schemas that have
`format === "datepicker"`
In example a custom validator that will be applied to schemas that have
`format === "datepicker"`
**AND**
`schema.required === true`
JSONEditor.defaults.custom_validators.push(function(schema, value, path) {
var errors = [];
...
...
@@ -148,7 +154,24 @@ In example a custo validator that will be applied to schemas that have `format =
return errors;
});
# add custom language error messages and set default language
now you can add a
`required`
property to the datepicker schema
"Datum": {
"title": 'Date',
"type": "string",
"format": "datepicker",
"datepickerOptions": {
"dateFormat": "dd-mm-yy",
"constrainInput": false,
"monthNames": [ "Januar", "Februar", "März", "April", "Mai", "Juni", "Juli", "August", "September", "Oktober", "November", "Dezember" ],
"dayNamesMin": [ "So", "Mo", "Di", "Mi", "Do", "Fr", "Sa" ],
"hideIfNoPrevNext": true,
"firstDay": 1
},
"required": true // <------- here
}
# Add custom language error messages and set default language
JSONEditor.defaults.language = "es";
...
...
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