add custom field "stringtemplate"

This commit is contained in:
tod31 2021-04-07 16:11:19 +02:00
parent 769bb7a55d
commit b8dc7ff18e
8 changed files with 104 additions and 2 deletions

View file

@ -234,3 +234,33 @@ CardCustomField.register('cardCustomField');
];
}
}.register('cardCustomField-dropdown'));
// cardCustomField-stringtemplate
(class extends CardCustomField {
onCreated() {
super.onCreated();
this.stringtemplateFormat = this.data().definition.settings.stringtemplateFormat;
}
formattedValue() {
lines = this.data().value.replace(/\r\n|\n\r|\n|\r/g, '\n').split('\n');
lines = lines.map(line =>
this.stringtemplateFormat.replace(/%\{value\}/gi, line)
);
return lines.join(' ');
}
events() {
return [
{
'submit .js-card-customfield-stringtemplate'(event) {
event.preventDefault();
const value = this.currentComponent().getValue();
this.card.setCustomField(this.customFieldId, value);
},
},
];
}
}.register('cardCustomField-stringtemplate'));