MSelect (.MSELECT)

A Vue custom Select element with search and validation.

Preview

Label1
Label2
Label3
Label4
Label5

Attributes

Nametypeoptionaldescription
optionsOptionAttrs[]falseto specify select options
v-model-falseto bind the input to a variable
idstringfalserequired for validating when using with MForm
requiredbooleantrueuse it to mark the field as required in MForm
placeholderstringtruesearch placeholder
multiplebooleantrueto allow multiple choices
borderedbooleantrueto get the bordered looking input
patternRegExtrueuse it to validate the user input with a specific pattern (indicates that this input is required)
invalidMessagestringtruewrite a message for invalid input
validMessagestringtruewrite a message for valid input
labelstringtrueto add a label to your input
transformer(string) => stringtrueto perform some transforming function on the text
maxLengthnumbertrueto add a maxlength and a counter
freeOptionsbooleantrueto allow users adding extra options

Usage

Make sure your data follow the OptionAttrs interface:

interface OptionAttrs {
  selected?: boolean;
  disabled?: boolean;
  value: string;
  label: string;
}

after that, you can add the data to the MSelect as in the example:

<MSelect
  id="preview-select"
  placeholder="MSelect"
  bordered
  :options="[
    { value: 'Option1', label: 'Label1', selected: true },
    { value: 'Option2', label: 'Label2', disabled: true },
    { value: 'Option3', label: 'Label3' },
    { value: 'Option4', label: 'Label4' },
    { value: 'Option5', label: 'Label5' },
  ]"
  v-model="selectedOption"
>
  <template #start>
    <i class="fas fa-caret-down"></i>
  </template>
</MSelect>