Search code examples
vue.jsvue-multiselect

How to invoke client side validation on vue-multiselect component?


I am using the vue-multiselect library like so:

in src/components/FeedbackForm.vue

<div>
<CustomerSelect :required="true" />
</div

Question: How can I make this select component required on the client-side? I thought I would be able to simply add an HTML5 attribute like so:

in src/components/CustomerSelect.vue

template section:

<multiselect
  id="customer_last_name_input"
  v-model="c_lastname_value"
  :options="getActiveUserProfiles"
  label="lastname"
  track-by="uid"
  :close-on-select="true"
  @select="onSelect"
  @remove="onRemove"
  required <----------can't do this?
>

script section:

props: ['required']

Doing the above code does not invoke client-side validation in the browser like a regular HTML select element. Thanks for any help.


Solution

  • As for docs it accepts a allowEmptybool prop.

    allowEmpty || Boolean || Allows to remove all selected values. Otherwise one must be left selected.

    so it would be

    <multiselect
      id="customer_last_name_input"
      v-model="c_lastname_value"
      :options="getActiveUserProfiles"
      label="lastname"
      track-by="uid"
      :close-on-select="true"
      @select="onSelect"
      @remove="onRemove"
      :allow-empty="required"  <----------do this?
    >