Comments (2)
Hi @simontaurus,
for default values there is the default
schema property
{
"type": "string",
"format": "date",
"default": "2022-02-02",
"template": "your_callback"
}
Editors with template
are read only because they are "generated" and very often overridden by the template expression / callback.
from json-editor.
Okay, so currently default
is the way to set a static value until the user overrides it. template
will enforce a dynamical value without any option for the user to change it (read-only). For usecases like the receiving_data of a shipment I'm looking for a way in between to set the current date (now
) as default but allow the user to change it to any other date (e. g. yesterday).
Setting a now
callback as template works but this renders the field as readonly.
{
"type": "string",
"format": "date",
"template": "now"
}
JSONEditor.defaults.callbacks = {
'now': (jseditor_editor, e) => {
return new Date(Date.now()).toISOString();
}
}
//or
Handlebars.registerHelper('now', function (options) {
return new Date(Date.now()).toISOString();
})
Setting now
as default keeps the field editable, but now
is not interpreted as template.
{
"type": "string",
"format": "date",
"default": "now",
}
A solution could be to allow templates in default values (see #142 (comment)), so that "default": "now"
or "default": "{{now}}"
is resolved to the current datetime (e.g. "default": "2024-02-04T04:31:08.050Z"
) at the initialisation of the editor but the user could still set another datetime.
from json-editor.
Related Issues (20)
- Hidden fields with dependencies disappear after setValue() HOT 1
- [question]How can i hide false ouput value on checkbox. HOT 2
- [question] How to get updated schema from json-editor after adding object field HOT 10
- Can I Do Dependencies Only On the Default Value And Enum? HOT 1
- [bug]select2 setValue report a error and not select it HOT 8
- Starrating format isn't working properly HOT 1
- bug/regression: bool or number value does not show when remove_empty_properties=true and use_default_values=false
- Can Do a "WACTH" To Another Root "JSON Editor". HOT 4
- Auto generate schema for simple cases HOT 5
- Support for chained / nested watch HOT 2
- Add meta-data (schema builder) example HOT 1
- Validation of datetime-local fails when oneOf is used HOT 3
- An error occurs when a dependency is defined after the field that depends on it HOT 1
- Dependent field does not update when watched field changes HOT 1
- Failure to parse schema with "default": null due to unhandled exception in browser console
- select2 doesn't refer enumSource of item in array. HOT 12
- How do I add my syntax highlighting to Ace Editor? HOT 1
- test
- Enum wont be selected on load if it not the first element HOT 2
- Dependencies with false values not fullfilled HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from json-editor.