Changed the behavior of `timestampTag` to fallback on the built-in rules when the function does not return a boolean. See #856.

This commit is contained in:
jos 2019-12-11 12:08:31 +01:00
parent 00c02b9bcf
commit 5c7e1e6fe9
3 changed files with 18 additions and 8 deletions

View File

@ -3,10 +3,12 @@
https://github.com/josdejong/jsoneditor
## 2019-12-11, version 7.6.0
## 2019-12-11, version 8.0.0
- Implemented option `timestampFormat` which allows customizing the formatting
of timestamp tags. See also option `timestampTag`. Thanks @smallp.
- Changed the behavior of `timestampTag` to fallback on the built-in rules when
the function does not return a boolean. See #856.
- Reverted the heuristics introduced in `v7.3.0` to check whether some field
contains a timestamp based on the field name, because they can give wrong
timestamps in case of values in seconds instead of the assumed milliseconds

View File

@ -476,8 +476,12 @@ Constructs a new JSONEditor.
than Jan 1th 2000, `946684800000`.
When `timestampTag` a is a function, a timestamp tag will be displayed when
this function returns `true`. The function is invoked with an object as first
parameter:
this function returns `true`, and no timestamp is displayed when the function
returns `false`. When the function returns a non-boolean value like `null`
or `undefined`, JSONEditor will fallback on the built-in rules to determine
whether or not to show a timestamp.
The function is invoked with an object as first parameter:
```
{

View File

@ -1961,19 +1961,23 @@ export class Node {
const timestampTag = this.editor.options.timestampTag
if (typeof timestampTag === 'function') {
return timestampTag({
const result = timestampTag({
field: this.field,
value: this.value,
path: this.getPath()
})
}
if (timestampTag === true) {
if (typeof result === 'boolean') {
return result
} else {
return isTimestamp(this.field, this.value)
}
} else if (timestampTag === true) {
return isTimestamp(this.field, this.value)
} else {
return false
}
}
/**
* Clear the dom of the node