Vue-multiselect: how to add class into vue-multiselect

Created on 7 Sep 2017  路  7Comments  路  Source: shentao/vue-multiselect

sorry if my title didn't seem to explain enough,
let's say i want to validate the form using other library,
any idea how to add the class?
since i use vee-validate it usually goes like this

:class="{'is-danger': errors.has('ca')}"

& 1 more thing, i know its silly, but how do i add the highlight to the input when focused?

invalid question

Most helpful comment

Why would you want to add a custom class to the <input> element? You know that the input is just a very small fragment of the component. It鈥檚 actually borderless and sometimes there鈥檚 no <input> at all. It would be useless.
If you add :class="{'is-danger': errors.has('ca')}" to the <multiselect> it will add that class to the root element of the component. You can then add the needed styles to change the border or whatever you wish to do with it.

Here鈥檚 an example: https://jsfiddle.net/shentao/qj7xovms/

All 7 comments

Adding a custom class to the input element isn't supported by this component, which I think is madness. At the moment you are forced to customise/override the default CSS.

This is really frustrating for me as I have a bunch of existing form styles that I want applied to this, and I'm going to need to duplicate them all.

@shentao how come this isn't in there? Seems like it would be fairly straight forward to add a "class" prop.

Why would you want to add a custom class to the <input> element? You know that the input is just a very small fragment of the component. It鈥檚 actually borderless and sometimes there鈥檚 no <input> at all. It would be useless.
If you add :class="{'is-danger': errors.has('ca')}" to the <multiselect> it will add that class to the root element of the component. You can then add the needed styles to change the border or whatever you wish to do with it.

Here鈥檚 an example: https://jsfiddle.net/shentao/qj7xovms/

Why this is closed?

@atrujillofalcon because it was answered above and I don鈥檛 consider this an actual issue.

in a specific template, we need a binding class in the input element, and if I binding in multi select it will have an issue in style
image

Using the binding option you always can do something like this:

<multiselect
:class="{'myclass': true, 'myotherclass': true}"
 v-model="mymodel"
></multiselect>

What I have found is that classes used into the component could conflict with some specific styling (validation background images with multiselect__tags class, for example, because it adds background color and the root div of the component have a z-index of -1).

you can override multiselect class like this

.multiselect__placeholder {
  display: inline-block !important;
  margin-bottom: 0px !important;
  padding-top: 0px !important;
}

.multiselect.invalid .multiselect__tags {
  border: 1px solid #f86c6b !important;
}

don't forget to remove scoped tag :)

Screenshot from 2020-12-03 00-24-49

Was this page helpful?
0 / 5 - 0 ratings

Related issues

zachleigh picture zachleigh  路  3Comments

xereda picture xereda  路  4Comments

shsmad picture shsmad  路  3Comments

PrimozRome picture PrimozRome  路  3Comments

MaxHalford picture MaxHalford  路  4Comments