Skip to content

required Validation Not Working When searchable is Set to false #1888

Open
@ashish0008

Description

@ashish0008

Title: required Validation Not Working When searchable is Set to false

Description

I encountered an issue where the required validation does not work when the searchable prop is set to false. By default, searchable is true, and the required validation works as expected. However, when I explicitly set searchable: false, the component allows form submission even when no option is selected.


Steps to Reproduce

  1. Use the <Multiselect> component with :searchable="false" and required inside a form.
  2. Do not select any option and try submitting the form.
  3. The form submits successfully, even though it should prevent submission due to the required field.

Expected Behavior

The required validation should work regardless of whether searchable is true or false. If no option is selected, the form should not be submitted.


Actual Behavior

When searchable is false, the required validation is ignored, and the form submits without any errors.


Reproducible Example (if applicable)

<template>
  <form @submit.prevent="submitForm">
    <multiselect
      v-model="selected"
      :options="['Option 1', 'Option 2']"
      :searchable="false"
      required
      placeholder="Select an option"
    />
    <button type="submit">Submit</button>
  </form>
</template>

<script>
import Multiselect from "vue-multiselect";
export default {
  components: { Multiselect },
  data() {
    return {
      selected: null,
    };
  },
  methods: {
    submitForm() {
        alert("Form submitted! This message should display only if option is selected");
    },
  },
};
</script>

Environment

  • Vue: 3.5.13
  • vue-multiselect: 3.2
  • Browser: Chrome v134

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions