An ES6 native replacement for select
using standards Bootstrap 5 styles.
No additional CSS needed! Supports creation of new tags.
import Tags from "./tags.js";
Tags.init();
By default, only provided options are available. Validation error will be displayed in case of invalid tag.
<label for="validationTags" class="form-label">Tags</label>
<select class="form-select" id="validationTags" name="tags[]" multiple>
<option selected disabled hidden value="">Choose a tag...</option>
<option value="1" selected="selected">Apple</option>
<option value="2">Banana</option>
<option value="3">Orange</option>
</select>
<div class="invalid-feedback">Please select a valid tag.</div>
Use attribute data-allow-new
to allow creation of new tags. Their
default value will be equal to the text. Since you can enter
arbitrary text, no validation will occur.
<select class="form-select" id="validationTags" name="tags[]" multiple data-allow-new="true">
NOTE: don't forget the [] if you need multiple values!
https://codepen.io/lekoalabe/pen/ExWYEqx
Maybe you can have a look at https://github.com/Honatas/multi-select-webcomponent