Skip to content

Commit f77a056

Browse files
fix: inline lookup option
1 parent 70eefd1 commit f77a056

File tree

1 file changed

+41
-29
lines changed
  • packages/Webkul/Admin/src/Resources/views/components/form/control-group/controls/inline

1 file changed

+41
-29
lines changed

packages/Webkul/Admin/src/Resources/views/components/form/control-group/controls/inline/lookup.blade.php

+41-29
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,13 @@ class="group relative h-[18px] !w-full pl-2.5"
3939
:style="{ 'text-align': position }"
4040
>
4141
<span class="cursor-pointer truncate rounded">
42-
@{{ valueLabel ? valueLabel : inputValue.length > 20 ? inputValue.substring(0, 20) + '...' : inputValue }}
42+
<template v-if="isDirty">
43+
@{{ inputValue.length > 20 ? inputValue.substring(0, 20) + '...' : inputValue }}
44+
</template>
45+
46+
<template v-else>
47+
@{{ valueLabel ? valueLabel : inputValue.length > 20 ? inputValue.substring(0, 20) + '...' : inputValue }}
48+
</template>
4349
</span>
4450
4551
<!-- Tooltip -->
@@ -62,7 +68,7 @@ class="icon-edit cursor-pointer rounded p-0.5 text-2xl opacity-0 hover:bg-gray-2
6268
></i>
6369
</template>
6470
</div>
65-
71+
6672
<!-- Editing view -->
6773
<div
6874
class="relative flex w-full flex-col"
@@ -75,7 +81,7 @@ class="relative flex w-full flex-col"
7581
class="!h-[34px] w-full cursor-pointer !py-0 text-gray-800 dark:text-white ltr:pr-20 rtl:pl-20"
7682
::placeholder="placeholder"
7783
v-model="selectedItem.name"
78-
@click="toggleEditor"
84+
@click="toggleEditor"
7985
readonly
8086
/>
8187
@@ -87,17 +93,17 @@ class="relative"
8793
>
8894
<x-admin::spinner />
8995
</div>
90-
91-
<i
96+
97+
<i
9298
class="text-2xl"
9399
:class="showPopup ? 'icon-up-arrow': 'icon-down-arrow'"
94100
></i>
95101
</div>
96102
</span>
97-
103+
98104
<!-- Popup Box -->
99-
<div
100-
v-if="showPopup"
105+
<div
106+
v-if="showPopup"
101107
class="absolute z-10 mt-1 w-full origin-top transform rounded-lg border border-gray-200 bg-white p-2 shadow-lg transition-transform dark:border-gray-800 dark:bg-gray-800"
102108
:class="dropdownPosition === 'bottom' ? 'top-full mt-1' : 'bottom-full mb-1'"
103109
>
@@ -110,24 +116,24 @@ class="!mb-2 w-full rounded border border-gray-200 px-2.5 py-2 text-sm font-norm
110116
placeholder="@lang('admin::app.components.lookup.search')"
111117
ref="searchInput"
112118
/>
113-
119+
114120
<!-- Results List -->
115121
<ul class="max-h-40 divide-y divide-gray-100 overflow-y-auto">
116-
<li
117-
v-for="item in filteredResults"
122+
<li
123+
v-for="item in filteredResults"
118124
:key="item.id"
119125
class="cursor-pointer px-4 py-2 text-gray-800 transition-colors hover:bg-blue-100 dark:text-white dark:hover:bg-gray-950"
120126
@click="selectItem(item)"
121127
>
122128
@{{ item.name }}
123129
</li>
124-
130+
125131
<li v-if="filteredResults.length === 0" class="px-4 py-2 text-center text-gray-500 dark:text-gray-300">
126132
@lang('admin::app.components.lookup.no-results')
127133
</li>
128134
</ul>
129135
</div>
130-
136+
131137
<!-- Action Buttons -->
132138
<div class="absolute top-1/2 flex -translate-y-1/2 transform gap-0.5 bg-white dark:bg-gray-900 ltr:right-2 rtl:left-2">
133139
<button
@@ -137,7 +143,7 @@ class="flex items-center justify-center bg-green-100 p-1 hover:bg-green-200 ltr:
137143
>
138144
<i class="icon-tick text-md cursor-pointer font-bold text-green-600 dark:!text-green-600" />
139145
</button>
140-
146+
141147
<button
142148
type="button"
143149
class="item-center flex justify-center bg-red-100 p-1 hover:bg-red-200 ltr:rounded-r-md rtl:rounded-l-md"
@@ -197,7 +203,7 @@ class="item-center flex justify-center bg-red-100 p-1 hover:bg-red-200 ltr:round
197203
type: String,
198204
default: '',
199205
},
200-
206+
201207
valueLabel: {
202208
type: String,
203209
default: '',
@@ -210,6 +216,8 @@ class="item-center flex justify-center bg-red-100 p-1 hover:bg-red-200 ltr:round
210216
211217
isEditing: false,
212218
219+
isDirty: false,
220+
213221
showPopup: false,
214222
215223
searchTerm: '',
@@ -233,8 +241,8 @@ class="item-center flex justify-center bg-red-100 p-1 hover:bg-red-200 ltr:round
233241
watch: {
234242
/**
235243
* Watch the value prop.
236-
*
237-
* @param {String} newValue
244+
*
245+
* @param {String} newValue
238246
*/
239247
value(newValue) {
240248
this.inputValue = newValue;
@@ -256,11 +264,11 @@ class="item-center flex justify-center bg-red-100 p-1 hover:bg-red-200 ltr:round
256264
257265
/**
258266
* Filter the searchedResults based on the search query.
259-
*
267+
*
260268
* @return {Array}
261269
*/
262270
filteredResults() {
263-
return this.searchedResults.filter(item =>
271+
return this.searchedResults.filter(item =>
264272
item.name.toLowerCase().includes(this.searchTerm.toLowerCase())
265273
);
266274
},
@@ -269,7 +277,7 @@ class="item-center flex justify-center bg-red-100 p-1 hover:bg-red-200 ltr:round
269277
methods: {
270278
/**
271279
* Toggle the input.
272-
*
280+
*
273281
* @return {void}
274282
*/
275283
toggle() {
@@ -296,7 +304,7 @@ class="item-center flex justify-center bg-red-100 p-1 hover:bg-red-200 ltr:round
296304
297305
/**
298306
* Save the input value.
299-
*
307+
*
300308
* @return {void}
301309
*/
302310
save() {
@@ -310,6 +318,8 @@ class="item-center flex justify-center bg-red-100 p-1 hover:bg-red-200 ltr:round
310318
return;
311319
}
312320
321+
this.isDirty = true;
322+
313323
this.inputValue = this.selectedItem.name;
314324
315325
if (this.url) {
@@ -320,10 +330,12 @@ class="item-center flex justify-center bg-red-100 p-1 hover:bg-red-200 ltr:round
320330
this.$emitter.emit('add-flash', { type: 'success', message: response.data.message });
321331
})
322332
.catch((error) => {
333+
this.isDirty = false;
334+
323335
this.inputValue = this.value;
324336
325337
this.$emitter.emit('add-flash', { type: 'error', message: error.response.data.message });
326-
});
338+
});
327339
}
328340
329341
this.$emit('on-change', {
@@ -334,9 +346,9 @@ class="item-center flex justify-center bg-red-100 p-1 hover:bg-red-200 ltr:round
334346
335347
/**
336348
* Select an item from the list.
337-
*
349+
*
338350
* @param {Object} item
339-
*
351+
*
340352
* @return {void}
341353
*/
342354
selectItem(item) {
@@ -349,7 +361,7 @@ class="item-center flex justify-center bg-red-100 p-1 hover:bg-red-200 ltr:round
349361
350362
/**
351363
* Cancel the input value.
352-
*
364+
*
353365
* @return {void}
354366
*/
355367
cancel() {
@@ -364,7 +376,7 @@ class="item-center flex justify-center bg-red-100 p-1 hover:bg-red-200 ltr:round
364376
365377
/**
366378
* Initialize the items.
367-
*
379+
*
368380
* @return {void}
369381
*/
370382
search() {
@@ -385,11 +397,11 @@ class="item-center flex justify-center bg-red-100 p-1 hover:bg-red-200 ltr:round
385397
this.cancelToken = this.$axios.CancelToken.source();
386398
387399
this.$axios.get(this.src, {
388-
params: {
400+
params: {
389401
...this.params,
390402
query: this.searchTerm
391403
},
392-
cancelToken: this.cancelToken.token,
404+
cancelToken: this.cancelToken.token,
393405
})
394406
.then(response => {
395407
this.searchedResults = response.data;
@@ -409,7 +421,7 @@ class="item-center flex justify-center bg-red-100 p-1 hover:bg-red-200 ltr:round
409421
const dropdownContainer = this.$refs.dropdownContainer;
410422
411423
if (! dropdownContainer) {
412-
return;
424+
return;
413425
}
414426
415427
const dropdownRect = dropdownContainer.getBoundingClientRect();

0 commit comments

Comments
 (0)