Skip to content

Commit

Permalink
fixed pgSlimSelect not being defined by correcting the assignment of … (
Browse files Browse the repository at this point in the history
#1251)

* fixed pgSlimSelect not being defined by correcting the assignment of the window.phSlimSelect object to window.pgSlimSelect

* updated slimselect structure ¿

* fix slimSelect settings

* Add package lock > gitignore

---------

Co-authored-by: luanfreitasdev <[email protected]>
  • Loading branch information
pablomadariaga and luanfreitasdev authored Nov 11, 2023
1 parent 3c7729c commit 8a34832
Show file tree
Hide file tree
Showing 7 changed files with 5,624 additions and 5,481 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ dist/powergrid.js.LICENSE.txt

tests/cypress/app/
.DS_Store
package-lock.json
2 changes: 1 addition & 1 deletion dist/mix-manifest.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"/powergrid.js": "/powergrid.js?id=9fecf3285b01d336e66f1f1f18b32bff",
"/powergrid.js": "/powergrid.js?id=c0ba3ef29bce8fed6df0b284053125a6",
"/bootstrap5.css": "/bootstrap5.css?id=03aba1df82c23db07c1d1096efcd42ae",
"/tailwind.css": "/tailwind.css?id=0a704dc8cc7a1f02d8000c080300b604",
"/tom-select.css": "/tom-select.css?id=7af730d2c4bf937316d4002948b1571d",
Expand Down
2 changes: 1 addition & 1 deletion dist/powergrid.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion resources/js/components/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ window.pgFlatpickr = pgFlatpickr
window.pgEditable = pgEditable
window.tableResponsive = tableResponsive
window.pgTomSelect = pgTomSelect
window.phSlimSelect = pgSlimSelect
window.pgSlimSelect = pgSlimSelect

Livewire.hook('commit', ({ component, succeed, fail }) => {
if (component.ephemeral.setUp && component.ephemeral.setUp.hasOwnProperty('responsive')) {
Expand Down
49 changes: 38 additions & 11 deletions resources/js/components/select/slimSelect.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,42 @@
import { storeMultiSelect } from "./store";

export default (params) => ({
init() {
const element = this.$refs['select_picker_'+params.dataField+'_'+params.tableName];

new window.SlimSelect(element,{
items: this.initialValues,
...this.framework,
onChange: (value) => {
storeMultiSelect(params, value)
},
});
initialValues: params.initialValues,
framework: params.framework,
init() {
const element =
this.$refs["select_picker_" + params.dataField + "_" + params.tableName];

const frameworkCopy = this.deepCopy(this.framework);

new window.SlimSelect({
select: element,
...frameworkCopy,
events: {
afterChange: (value) => {
let newValue = value.map(item => item.value);
storeMultiSelect(params, newValue);
},
},
});
},
deepCopy(obj) {
if (obj === null || typeof obj !== 'object') {
return obj;
}

if (Array.isArray(obj)) {
return obj.map(this.deepCopy);
}
})

const copy = {};
for (const key in obj) {
if (obj.hasOwnProperty(key)) {
copy[key] = this.deepCopy(obj[key]);
}
}

return copy;
}
});

8 changes: 4 additions & 4 deletions resources/views/components/inputs/select.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
@php
$framework = config('livewire-powergrid.plugins.select');
$collection = collect();
if (filled(data_get($filter, 'dataSource'))) {
$collection = collect(data_get($filter, 'dataSource'))->transform(function (array|\Illuminate\Support\Collection|\Illuminate\Database\Eloquent\Model $entry) use ($filter) {
if (is_array($entry)) {
Expand All @@ -19,7 +19,7 @@
return $entry->only([data_get($filter, 'optionValue'), data_get($filter, 'optionLabel')]);
});
}
$params = [
'tableName' => $tableName,
'label' => data_get($filter, 'title'),
Expand All @@ -29,7 +29,7 @@
'initialValues' => $initialValues,
'framework' => $framework[config('livewire-powergrid.plugins.select.default')],
];
if (\Illuminate\Support\Arr::has($filter, ['url', 'method'])) {
$params['asyncData'] = [
'url' => data_get($filter, 'url'),
Expand All @@ -38,7 +38,7 @@
'headers' => data_get($filter, 'headers'),
];
}
$alpineData = $framework['default'] == 'tom' ? 'pgTomSelect(' . \Illuminate\Support\Js::from($params) . ')' : 'pgSlimSelect(' . \Illuminate\Support\Js::from($params) . ')';
@endphp
<div
Expand Down
Loading

0 comments on commit 8a34832

Please sign in to comment.