2
0
mirror of https://github.com/frappe/books.git synced 2024-09-20 03:29:00 +00:00

fix(ux): allow custom empty messages in autocomp

- set custom message for State
This commit is contained in:
18alantom 2022-01-12 15:04:16 +05:30
parent 404cb60cc1
commit 7878a405d3
3 changed files with 27 additions and 3 deletions

View File

@ -50,6 +50,12 @@ export default {
label: 'State', label: 'State',
placeholder: 'State', placeholder: 'State',
fieldtype: 'AutoComplete', fieldtype: 'AutoComplete',
emptyMessage: (doc) => {
if (doc.country) {
return 'Enter State';
}
return 'Enter Country to load States';
},
getList: getStates, getList: getStates,
}, },
{ {

View File

@ -1,5 +1,5 @@
<template> <template>
<Dropdown :items="suggestions" :is-loading="isLoading"> <Dropdown :items="suggestions" :is-loading="isLoading" :df="df" :doc="doc">
<template <template
v-slot="{ v-slot="{
toggleDropdown, toggleDropdown,

View File

@ -21,8 +21,11 @@
<div v-if="isLoading" class="p-2 text-gray-600 italic"> <div v-if="isLoading" class="p-2 text-gray-600 italic">
{{ _('Loading...') }} {{ _('Loading...') }}
</div> </div>
<div v-if="!isLoading && dropdownItems.length === 0" class="p-2 text-gray-600 italic"> <div
{{ _('Empty') }} v-if="!isLoading && dropdownItems.length === 0"
class="p-2 text-gray-600 italic"
>
{{ getEmptyMessage() }}
</div> </div>
<template v-else> <template v-else>
<div v-for="d in dropdownItems" :key="d.label"> <div v-for="d in dropdownItems" :key="d.label">
@ -92,6 +95,12 @@ export default {
type: Boolean, type: Boolean,
default: false, default: false,
}, },
df: {
default: null,
},
doc: {
default: null,
},
}, },
components: { components: {
Popover, Popover,
@ -156,6 +165,15 @@ export default {
}, },
}, },
methods: { methods: {
getEmptyMessage() {
const { emptyMessage } = this.df ?? {};
if (typeof emptyMessage === 'function') {
return _(emptyMessage(this.doc));
} else if (emptyMessage) {
return _(emptyMessage);
}
return _('Empty');
},
selectItem(d) { selectItem(d) {
if (d.action) { if (d.action) {
d.action(); d.action();