Git Product home page Git Product logo

Comments (3)

adamberecz avatar adamberecz commented on July 22, 2024

This is because you need to set options before you set the values:

created() {
  this.options = [...data]
}

Also the search method seems redundant, Multiselect should filter the results automatically.

from multiselect.

negezor avatar negezor commented on July 22, 2024

This is a simple example for clarity. In my case, reactive search options are used that I get from the GraphQL API. As well as the data that was received initially from the API. I am thinking about merge options that are pre-passed to v-model.

// BaseSearch.vue

<template>
	<Multiselect
		v-model="model"
		v-bind="$attrs"
		:object="true"
		:searchable="true"
		:loading="loading"
		:options="selectOptions"
		value-prop="id"
		track-by="name"
		label="name"
		@search-change="search"
	/>
</template>

<script lang="ts">
import {
	PropType,

	defineComponent,
	computed,
	ref
} from '@vue/composition-api';

import Multiselect from '@vueform/multiselect/dist/multiselect.vue2';

import { useSearchQuery } from '@/graphql';

export default defineComponent({
	components: {
		Multiselect
	},
	props: {
		value: {
			type: [Array, Object, String, Boolean, Number] as PropType<any>
		},
		type: {
			type: String as PropType<'USER' | 'TAG'>,
			required: true
		}
	} as const,
	setup(props, { emit }) {
		const model = computed({
			get: () => props.value,
			set: (value: any) => {
				emit('input', value);
			}
		});

		const variables = ref({});

		const { loading, result } = useSearchQuery(variables);

		const relayConnection = computed(() => (
			result.value?.search || {
				edges: []
			}
		));

		const selectOptions = computed(() => (
			relayConnection.value.edges.map(edge => edge.node)
		));

		const search = (query: string) => {
			if (!query) {
				return;
			}

			variables.value = {
				query,

				type: props.type
			};
		};

		return {
			model,

			loading,
			selectOptions,

			search
		};
	}
});
</script>

My example usage

<BaseSearch
	v-model="mainteners"
	mode="tags"
	type="USER"
/>
// ...

setup(props) {
  const mainteners = ref(props.mainteners);

  const updateMainteners = {...};

  return { mainteners, updateMainteners };
}

from multiselect.

adamberecz avatar adamberecz commented on July 22, 2024

Now if you update to 1.4.0 I believe your initial example will work. I guess that solves the original problem.

from multiselect.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.