Introducing ReUI:Open-source UI components and apps built with React, Next.js and Tailwind CSS
Browse ReUI

Select2 is destroyed in Form Single Vue File


I have form layout in one Vue file. I use v-if directive to show html based on step.
Initially when the DOM loads select2 is loaded and is working but when on the page i hit Next button to show other html in the same file, and thne goes back to Previous step to show the HTML, Select2 is destroyed.

Here is my code
Layout file

<script setup>
import { ref, onMounted } from "vue";
import ApplicationLogo from "@/Components/ApplicationLogo.vue";
import { Link } from "@inertiajs/vue3";

import "../../../public/assets/js/custom/documentation/select2.js"

onMounted(() => {
// Layout partials initialization
KTComponents.init();
// initializeSelect2();
})


</script>


<template>
<div class="d-flex flex-column flex-root" id="kt_app_root">
<div class="d-flex flex-column flex-lg-row flex-column-fluid">
<!--begin::Aside-->
<div class="d-flex flex-lg-row-fluid">
<!--begin::Content-->
<div class="d-flex flex-column flex-center pb-0 pb-lg-10 p-10 w-100">
<!--begin::Image-->
<img class="theme-light-show mx-auto mw-100 w-150px w-lg-300px mb-10 mb-lg-20"
src="assets/media/auth/agency.png" alt="" />
<img class="theme-dark-show mx-auto mw-100 w-150px w-lg-300px mb-10 mb-lg-20"
src="assets/media/auth/agency-dark.png" alt="" />
<!--end::Image-->
<!--begin::Title-->
<h1 class="text-gray-800 fs-2qx fw-bold text-center mb-7">Fast, Efficient and Productive</h1>
<!--end::Title-->
<!--begin::Text-->
<div class="text-gray-600 fs-base text-center fw-semibold">In this kind of post,
<a href="#%22%20class=%22opacity-75-hover%20text-primary%20me-1" target="_blank" rel="noopener noreferrer">the blogger</a>introduces a person
they&rsquo;ve interviewed
<br />and provides some background information about
<a href="#%22%20class=%22opacity-75-hover%20text-primary%20me-1" target="_blank" rel="noopener noreferrer">the interviewee</a>and their
<br />work following this is a transcript of the interview.
</div>
<!--end::Text-->
</div>
<!--end::Content-->
</div>
<!--begin::Aside-->
<!--begin::Body-->
<div class="d-flex flex-column-fluid flex-lg-row-auto justify-content-center justify-content-lg-end p-12">
<!--begin::Wrapper-->
<div class="bg-body d-flex flex-column flex-center rounded-4 w-md-600px p-10">
<!--begin::Content-->
<div class="d-flex flex-center flex-column align-items-stretch h-lg-100 w-md-500px">
<!--begin::Wrapper-->
<div class="d-flex flex-center flex-column flex-column-fluid pb-15 pb-lg-20">
<slot />
</div>
</div>
</div>
</div>
</div>
</div>
</template>


Vue Component File

<script setup>
import GuestLayout from "@/Layouts/GuestLayout.vue";
import InputError from "@/Components/InputError.vue";
import InputLabel from "@/Components/InputLabel.vue";
import PrimaryButton from "@/Components/PrimaryButton.vue";
import TextInput from "@/Components/TextInput.vue";
import Select from "@/Components/Select.vue";
import { Head, Link, useForm } from "@inertiajs/vue3";
import { ref, onMounted } from "vue"


const form = useForm({
first_name: "",
last_name: "",
email: "",
password: "",
password_confirmation: "",
category_id: "",
industry_id: "",
location_name: "",
company_name: "",
});
const selectedOption = ref("");
const categories = [
{ value: "0", label: "Company" },
{ value: "1", label: "Individual" },
];
const props = defineProps({
industries: {
type: Array
},
countries: {
type: Array
},
errors: {
type: Object,
required: false, // Adjust based on your needs
},

});

const submit = () => {
form.post(route("register"), {
onFinish: () => form.reset("password", "password_confirmation"),
});
};

const formStep = ref(1);

const nextStep = () => {
formStep.value++;
};

const prevStep = () => {
formStep.value--;
};

</script>


<template>
<GuestLayout>

<Head title="Register" />

<form @submit.prevent="submit" class="form-inline w-100">
<div class="text-center mb-11">
<!--begin::Title-->
<h1 v-if="formStep == 1" class="text-gray-900 fw-bolder mb-3">
Account
</h1>
<h1 v-if="formStep == 2" class="text-gray-900 fw-bolder mb-3">
Registration
</h1>
<h1 v-if="formStep == 3" class="text-gray-900 fw-bolder mb-3">
Location
</h1>
<!--end::Title-->
</div>
<div v-if="errors">
<p v-for="error in errors" :key="error.field" class="text-danger">{{ error }}</p>
</div>
<div v-if="formStep == 1">
<div class="row">
<div class="col-6 mb-3">
<InputLabel for="category" value="Category" />
<Select :options="categories" id="category_id" class="form-select mt-1" v-model="form.category_id"></Select>
<InputError class="mt-2" :message="form.errors.category_id" />
</div>

<div class="col-6 mb-3">
<InputLabel for="industry" value="Industry" />
<Select :options="industries" class="form-select mt-1" v-model="form.industry_id"></Select>
<InputError class="mt-2" :message="form.errors.industry_id" />
</div>
</div>



</div>

<!-- Step 2 - Organization Information Fields: Starts-->
<div v-if="formStep == 2">
<div class="row">
<div class="mb-3">
<InputLabel for="company_name" value="Company Name" />
<TextInput id="company_name" type="text" class="form-control mt-1" v-model="form.company_name"
required autofocus autocomplete="company_name" />
<InputError class="mt-2 text-danger" :message="form.errors.company_name" />
</div>
</div>
</div>

<!-- Step 2 - Organization Information Fields: End-->
<!--begin::Submit button-->
<div class="d-flex justify-content-between align-center mb-10">
<!--begin::Sign up-->
<div class="text-gray-500 text-center fw-semibold fs-6" v-if="formStep == 1">
<Link :href="route("login")" class="btn btn-dark fw-semibold">
Already registered?
</Link>
</div>
<!--end::Sign up-->
<PrimaryButton type="button" id="kt_sign_up_submit" class="btn btn-primary" v-if="formStep == 1"
@click="nextStep" :class="{ "opacity-50": form.processing }" :disabled="form.processing">
<!--begin::Indicator label-->
<span class="indicator-label">Next</span>
<!--end::Indicator label-->
<!--begin::Indicator progress-->
<span class="indicator-progress">Please wait...
<span class="spinner-border spinner-border-sm align-middle ms-2"></span></span>
<!--end::Indicator progress-->
</PrimaryButton>

<PrimaryButton type="button" id="kt_sign_up_submit" class="btn btn-dark" v-if="formStep == 2"
@click="prevStep" :class="{ "opacity-50": form.processing }" :disabled="form.processing">
<!--begin::Indicator label-->
<span class="indicator-label">Previous</span>
<!--end::Indicator label-->
<!--begin::Indicator progress-->
<span class="indicator-progress">Please wait...
<span class="spinner-border spinner-border-sm align-middle ms-2"></span></span>
<!--end::Indicator progress-->
</PrimaryButton>

<PrimaryButton type="submit" id="kt_sign_up_submit" class="btn btn-primary" v-if="formStep == 2"
:class="{ "opacity-50": form.processing }" :disabled="form.processing">
<!--begin::Indicator label-->
<span class="indicator-label">Next</span>
<!--end::Indicator label-->
<!--begin::Indicator progress-->
<span class="indicator-progress">Please wait...
<span class="spinner-border spinner-border-sm align-middle ms-2"></span></span>
<!--end::Indicator progress-->
</PrimaryButton>
</div>
<!--end::Submit button-->

</form>
</GuestLayout>
</template>


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)


مرحباً، لقد أبهرني موقع www.mostbet-egp.bet بعروضه الرائعة للمراهنة والمقامرة. أنا أحب الرياضة، لذا فإن القدرة على المراهنة على رياضات مختلفة وبأشكال مختلفة أمر يسعدني للغاية. يسعدني بشكل خاص أن الموقع ليس فقط الرهانات التقليدية ولكن أيضًا فرصة المشاركة في الرهانات الحية، مما يضيف المزيد من الأدرينالين إلى اللعبة. بالإضافة إلى ذلك، فقد ساعدتني المكافآت والعروض الترويجية التي تقدمها المنصة على تحسين تجربة اللعب بشكل كبير. أوصي بـ MostBet لأي شخص يريد الاستمتاع بالمراهنة على مستوى عالٍ!



Hi,

Thank you for reaching out to us.

Did you import the select2 styles?


import "assets/plugins/global/plugins.bundle.css"


You can find usage examples in our select2 documentation.
https://preview.keenthemes.com/html/metronic/docs/forms/select2

Regards,
Lauris Stepanovs,
Keenthemes Support Team


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  :(