GithubHelp home page GithubHelp logo

Comments (2)

germanbisurgi avatar germanbisurgi commented on May 23, 2024

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.

simontaurus avatar simontaurus commented on May 23, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.