2
0
mirror of https://github.com/frappe/books.git synced 2024-11-10 15:50:56 +00:00

New Item defaults are set according to filters

This commit is contained in:
thefalconx33 2019-07-16 18:25:16 +05:30
parent 31129a04c2
commit 5eae951c92

View File

@ -42,6 +42,7 @@ export default {
})) }))
.concat({ .concat({
label: plusIcon + ' New ' + this.getTarget(), label: plusIcon + ' New ' + this.getTarget(),
filters,
value: '__newItem' value: '__newItem'
}); });
}, },
@ -138,18 +139,23 @@ export default {
}, },
onItemClick(item) { onItemClick(item) {
if (item.value === '__newItem') { if (item.value === '__newItem') {
this.openFormModal(); this.openFormModal(item.filters);
} else { } else {
this.handleChange(item.value); this.handleChange(item.value);
} }
}, },
async openFormModal() { async openFormModal(filters) {
const input = this.$refs.input; const input = this.$refs.input;
const newDoc = await frappe.getNewDoc(this.getTarget()); const newDoc = await frappe.getNewDoc(this.getTarget());
let defaultValues = {};
if (filters) {
for (let key of Object.keys(filters)) {
defaultValues[key] = filters[key];
}
}
defaultValues.name = input.value !== '__newItem' ? input.value : null;
this.$formModal.open(newDoc, { this.$formModal.open(newDoc, {
defaultValues: { defaultValues,
name: input.value !== '__newItem' ? input.value : null
},
onClose: () => { onClose: () => {
// if new doc was not created // if new doc was not created
// then reset the input value // then reset the input value