2
0
mirror of https://github.com/frappe/books.git synced 2025-01-12 19:06:38 +00:00

Input Description & Dynamic Labels

This commit is contained in:
thefalconx33 2019-09-03 16:13:05 +05:30
parent 2a1673dfe3
commit 82fb95debc
2 changed files with 32 additions and 2 deletions

View File

@ -49,6 +49,7 @@ export default {
});
}
});
this.setLabelOptions();
},
methods: {
getDocField(fieldname) {
@ -72,6 +73,13 @@ export default {
return true;
},
setLabelOptions() {
this.fields.forEach(field => {
if (field.labelOption) {
field.labelOption = field.labelOption(this.doc);
}
});
},
updateDoc(fieldname, value) {
this.doc.set(fieldname, value);
this.$emit('updateDoc', {

View File

@ -61,16 +61,38 @@ export default {
);
},
getChildrenElement(h) {
return [this.getLabelElement(h), this.getInputElement(h)];
return [
this.getLabelElement(h),
this.getInputElement(h),
this.getDescriptionElement(h)
];
},
getLabelElement(h) {
const hasLabelOptions = Boolean(this.docfield.labelOption);
let label = this.docfield.label;
if (hasLabelOptions) {
const replaceableKeys = Object.keys(this.docfield.labelOption);
for (let key of replaceableKeys) {
label = label.replace(key.toString(), this.docfield.labelOption[key]);
}
}
return h('label', {
class: [this.labelClass, 'text-muted'],
attrs: {
for: this.id
},
domProps: {
textContent: this.docfield.label
textContent: label
}
});
},
getDescriptionElement(h) {
return h('small', {
class: ['form-text', 'text-muted'],
domProps: {
textContent: this.docfield.description || ''
}
});
},