Squashed commit of the following:
commit 4aa3e04df0
Author: smilerz <smilerz@gmail.com>
Date: Wed Sep 6 09:01:07 2023 -0500
clears search on food in shopping form
This commit is contained in:
parent
9e831a22df
commit
847fceaf10
@ -4,7 +4,7 @@
|
|||||||
v-model="selected_objects"
|
v-model="selected_objects"
|
||||||
:options="objects"
|
:options="objects"
|
||||||
:close-on-select="true"
|
:close-on-select="true"
|
||||||
:clear-on-select="multiple"
|
:clear-on-select="true"
|
||||||
:hide-selected="multiple"
|
:hide-selected="multiple"
|
||||||
:preserve-search="true"
|
:preserve-search="true"
|
||||||
:internal-search="false"
|
:internal-search="false"
|
||||||
@ -27,11 +27,11 @@
|
|||||||
<script>
|
<script>
|
||||||
import Vue from "vue"
|
import Vue from "vue"
|
||||||
import Multiselect from "vue-multiselect"
|
import Multiselect from "vue-multiselect"
|
||||||
import {ApiMixin, StandardToasts} from "@/utils/utils"
|
import { ApiMixin, StandardToasts } from "@/utils/utils"
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: "GenericMultiselect",
|
name: "GenericMultiselect",
|
||||||
components: {Multiselect},
|
components: { Multiselect },
|
||||||
mixins: [ApiMixin],
|
mixins: [ApiMixin],
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
@ -43,16 +43,16 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
props: {
|
props: {
|
||||||
placeholder: {type: String, default: undefined},
|
placeholder: { type: String, default: undefined },
|
||||||
model: {
|
model: {
|
||||||
type: Object,
|
type: Object,
|
||||||
default() {
|
default() {
|
||||||
return {}
|
return {}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
label: {type: String, default: "name"},
|
label: { type: String, default: "name" },
|
||||||
parent_variable: {type: String, default: undefined},
|
parent_variable: { type: String, default: undefined },
|
||||||
limit: {type: Number, default: 25},
|
limit: { type: Number, default: 25 },
|
||||||
sticky_options: {
|
sticky_options: {
|
||||||
type: Array,
|
type: Array,
|
||||||
default() {
|
default() {
|
||||||
@ -69,11 +69,11 @@ export default {
|
|||||||
type: Object,
|
type: Object,
|
||||||
default: undefined,
|
default: undefined,
|
||||||
},
|
},
|
||||||
search_on_load: {type: Boolean, default: true},
|
search_on_load: { type: Boolean, default: true },
|
||||||
multiple: {type: Boolean, default: true},
|
multiple: { type: Boolean, default: true },
|
||||||
allow_create: {type: Boolean, default: false},
|
allow_create: { type: Boolean, default: false },
|
||||||
create_placeholder: {type: String, default: "You Forgot to Add a Tag Placeholder"},
|
create_placeholder: { type: String, default: "You Forgot to Add a Tag Placeholder" },
|
||||||
clear: {type: Number},
|
clear: { type: Number },
|
||||||
},
|
},
|
||||||
watch: {
|
watch: {
|
||||||
initial_selection: function (newVal, oldVal) {
|
initial_selection: function (newVal, oldVal) {
|
||||||
@ -84,12 +84,12 @@ export default {
|
|||||||
empty[this.label] = `..${this.$t("loading")}..`
|
empty[this.label] = `..${this.$t("loading")}..`
|
||||||
this.selected_objects.forEach((x) => {
|
this.selected_objects.forEach((x) => {
|
||||||
if (typeof x !== "object") {
|
if (typeof x !== "object") {
|
||||||
this.selected_objects[this.selected_objects.indexOf(x)] = {...empty, id: x}
|
this.selected_objects[this.selected_objects.indexOf(x)] = { ...empty, id: x }
|
||||||
get_details.push(x)
|
get_details.push(x)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
get_details.forEach((x) => {
|
get_details.forEach((x) => {
|
||||||
this.genericAPI(this.model, this.Actions.FETCH, {id: x})
|
this.genericAPI(this.model, this.Actions.FETCH, { id: x })
|
||||||
.then((result) => {
|
.then((result) => {
|
||||||
// this.selected_objects[this.selected_objects.map((y) => y.id).indexOf(x)] = result.data
|
// this.selected_objects[this.selected_objects.map((y) => y.id).indexOf(x)] = result.data
|
||||||
Vue.set(this.selected_objects, this.selected_objects.map((y) => y.id).indexOf(x), result.data)
|
Vue.set(this.selected_objects, this.selected_objects.map((y) => y.id).indexOf(x), result.data)
|
||||||
@ -105,8 +105,8 @@ export default {
|
|||||||
if (typeof this.selected_objects !== "object") {
|
if (typeof this.selected_objects !== "object") {
|
||||||
let empty = {}
|
let empty = {}
|
||||||
empty[this.label] = `..${this.$t("loading")}..`
|
empty[this.label] = `..${this.$t("loading")}..`
|
||||||
this.selected_objects = {...empty, id: this.selected_objects}
|
this.selected_objects = { ...empty, id: this.selected_objects }
|
||||||
this.genericAPI(this.model, this.Actions.FETCH, {id: this.selected_objects})
|
this.genericAPI(this.model, this.Actions.FETCH, { id: this.selected_objects })
|
||||||
.then((result) => {
|
.then((result) => {
|
||||||
this.selected_objects = result.data
|
this.selected_objects = result.data
|
||||||
})
|
})
|
||||||
@ -149,13 +149,12 @@ export default {
|
|||||||
methods: {
|
methods: {
|
||||||
// this.genericAPI inherited from ApiMixin
|
// this.genericAPI inherited from ApiMixin
|
||||||
search: function (query) {
|
search: function (query) {
|
||||||
|
|
||||||
let options = {
|
let options = {
|
||||||
page: 1,
|
page: 1,
|
||||||
pageSize: this.limit,
|
pageSize: this.limit,
|
||||||
query: query,
|
query: query,
|
||||||
limit: this.limit,
|
limit: this.limit,
|
||||||
options: {query: {simple: 1}}, // for API endpoints that support a simple view
|
options: { query: { simple: 1 } }, // for API endpoints that support a simple view
|
||||||
}
|
}
|
||||||
|
|
||||||
this.genericAPI(this.model, this.Actions.LIST, options).then((result) => {
|
this.genericAPI(this.model, this.Actions.LIST, options).then((result) => {
|
||||||
@ -183,24 +182,26 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
selectionChanged: function () {
|
selectionChanged: function () {
|
||||||
this.$emit("change", {var: this.parent_variable, val: this.selected_objects})
|
this.$emit("change", { var: this.parent_variable, val: this.selected_objects })
|
||||||
},
|
},
|
||||||
addNew(e) {
|
addNew(e) {
|
||||||
//TODO add ability to choose field name other than "name"
|
//TODO add ability to choose field name other than "name"
|
||||||
console.log('CREATEING NEW with -> ', e)
|
console.log("CREATEING NEW with -> ", e)
|
||||||
this.genericAPI(this.model, this.Actions.CREATE, {name: e}).then(result => {
|
this.genericAPI(this.model, this.Actions.CREATE, { name: e })
|
||||||
let createdObj = result.data?.results ?? result.data
|
.then((result) => {
|
||||||
StandardToasts.makeStandardToast(this, StandardToasts.SUCCESS_CREATE)
|
let createdObj = result.data?.results ?? result.data
|
||||||
if (this.multiple) {
|
StandardToasts.makeStandardToast(this, StandardToasts.SUCCESS_CREATE)
|
||||||
this.selected_objects.push(createdObj)
|
if (this.multiple) {
|
||||||
} else {
|
this.selected_objects.push(createdObj)
|
||||||
this.selected_objects = createdObj
|
} else {
|
||||||
}
|
this.selected_objects = createdObj
|
||||||
this.objects.push(createdObj)
|
}
|
||||||
this.selectionChanged()
|
this.objects.push(createdObj)
|
||||||
}).catch((r, err) => {
|
this.selectionChanged()
|
||||||
StandardToasts.makeStandardToast(this, StandardToasts.FAIL_CREATE)
|
})
|
||||||
})
|
.catch((r, err) => {
|
||||||
|
StandardToasts.makeStandardToast(this, StandardToasts.FAIL_CREATE)
|
||||||
|
})
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user