mirror of
https://github.com/wekan/wekan.git
synced 2025-04-22 04:57:07 -04:00
CustomFieldStringTemplate regular expressions of format field now possible
the new syntax is e.g.: ${regex:".(.*).", replace:"$1", flags:"i"} removes the first and last character and uses case-insensitive search. See also: https://developer.mozilla.org/de/docs/Web/JavaScript/Reference/Global_Objects/RegExp
This commit is contained in:
parent
2e996712f8
commit
d7f451a7d9
1 changed files with 20 additions and 2 deletions
|
@ -256,10 +256,28 @@ CardCustomField.register('cardCustomField');
|
|||
}
|
||||
|
||||
formattedValue() {
|
||||
return (this.data().value ?? [])
|
||||
const ret = (this.data().value ?? [])
|
||||
.filter(value => !!value.trim())
|
||||
.map(value => this.stringtemplateFormat.replace(/%\{value\}/gi, value))
|
||||
.map(value => {
|
||||
let _ret = this.stringtemplateFormat.replace(/[%$]\{.+?\}/g, function(_match) {
|
||||
let __ret;
|
||||
if (_match.match(/%\{value\}/i)) {
|
||||
__ret = value;
|
||||
} else {
|
||||
_match = _match.replace(/^\$/, "");
|
||||
try {
|
||||
const _json = JSON.parse(_match);
|
||||
__ret = value.replace(new RegExp(_json.regex, _json.flags), _json.replace);
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
}
|
||||
}
|
||||
return __ret;
|
||||
});
|
||||
return _ret;
|
||||
})
|
||||
.join(this.stringtemplateSeparator ?? '');
|
||||
return ret;
|
||||
}
|
||||
|
||||
getItems() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue