Open-source by Keenthemes!Support our KtUI and ReUI open-source projects and help with growth.
Star on Github

Vue Demo | Select with search


Hello,
I want to implement select with the search but I am not able to do so and not even found any example of select with search on Vue demo.

// Select element

<!--begin::Select-->
<Field name="productId" data-control="select2" data-hide-search="true" data-placeholder="Select Product" class="form-select form-select-solid" as="select" v-model="apiData.productId" @change="setAdditionalOption(apiData.productId)">
<option value="">Select Product</option>
<option v-for="productDetail in product" :value="productDetail.product_id" :key="productDetail">
{{productDetail.product_name}}
</option>
</Field>
<div class="fv-plugins-message-container">
<div class="fv-help-block">
<ErrorMessage name="productId" />
</div>
</div>
<!--end::Select-->


Screenshot:


Text formatting options
Submit
Here's a how to add some HTML formatting to your comment:
  • <pre></pre> for JS codes block
  • <pre lang="html"></pre> for HTML code block
  • <pre lang="scss"></pre> for SCSS code block
  • <pre lang="php"></pre> for PHP code block
  • <code></code> for single line of code
  • <strong></strong> to make things bold
  • <em></em> to emphasize
  • <ul><li></li></ul>  to make list
  • <ol><li></li></ol>  to make ordered list
  • <h3></h3> to make headings
  • <a></a> for links
  • <img> to paste in an image
  • <blockquote></blockquote> to quote somebody
  • happy  :)
  • shocked  :|
  • sad  :(

Replies (2)


@block blast!
ref="productSelect": Used to get a direct reference to the <select> element in the DOM.
mounted() and beforeUnmount(): Ensures select2 is initialized when the component is ready and destroyed when it's no longer needed.
selectedProductId as internal data: It's generally better to use an internal data property for v-model with third-party libraries that directly manipulate the DOM. You can then watch this property.
watch for selectedProductId: When selectedProductId changes (either internally or via a prop), select2 is programmatically updated.
.on('change', function ( ) { ... }): This is crucial. It listens for select2's change event and updates Vue's selectedProductId accordingly, maintaining the data flow.



You can use Element Plus select components with a filterable option.


Or Vue-multiselect plugin
https://preview.keenthemes.com/metronic8/vue/docs/#/vue-select#example4

To enable a search set searchable: true,.


Text formatting options
Submit
Here's a how to add some HTML formatting to your comment:
  • <pre></pre> for JS codes block
  • <pre lang="html"></pre> for HTML code block
  • <pre lang="scss"></pre> for SCSS code block
  • <pre lang="php"></pre> for PHP code block
  • <code></code> for single line of code
  • <strong></strong> to make things bold
  • <em></em> to emphasize
  • <ul><li></li></ul>  to make list
  • <ol><li></li></ol>  to make ordered list
  • <h3></h3> to make headings
  • <a></a> for links
  • <img> to paste in an image
  • <blockquote></blockquote> to quote somebody
  • happy  :)
  • shocked  :|
  • sad  :(
Text formatting options
Submit
Here's a how to add some HTML formatting to your comment:
  • <pre></pre> for JS codes block
  • <pre lang="html"></pre> for HTML code block
  • <pre lang="scss"></pre> for SCSS code block
  • <pre lang="php"></pre> for PHP code block
  • <code></code> for single line of code
  • <strong></strong> to make things bold
  • <em></em> to emphasize
  • <ul><li></li></ul>  to make list
  • <ol><li></li></ol>  to make ordered list
  • <h3></h3> to make headings
  • <a></a> for links
  • <img> to paste in an image
  • <blockquote></blockquote> to quote somebody
  • happy  :)
  • shocked  :|
  • sad  :(