javascriptjquerybootstrap-4jquery-bootgridjquery-bootpag

bootstrap multiselect dropdown+disable uncheck for particular option


How I can disable uncheck option from the bootstrap multi-select drop-down, actually on load some option by default is checked and I want those options not to be unchecked. Below I am providing an image for better understanding. ! [Link for the sample image] 1

From the above image those three is by default checked while page load and now I don't want to be unchecked those three (Cheese, Tomatoes, Mozzarella)

Below I am providing the link of the above requirement. Link to the sample code

Thanks


Solution

  • You can just simply add disabled (and selected) attributes to the options which you want to keep selected.

    <div class="form-group">
        <label class="col-md-4 control-label" for="rolename">Role Name</label>
        <div class="col-md-4">
            <select id="dates-field2" class="multiselect-ui form-control" multiple="multiple">
                <option value="cheese" disabled selected>Cheese</option>
                <option value="tomatoes" disabled selected>Tomatoes</option>
                <option value="mozarella" disabled selected>Mozzarella</option>
                <option value="mushrooms">Mushrooms</option>
                <option value="pepperoni">Pepperoni</option>
                <option value="onions">Onions</option>
            </select>
        </div>
    </div>
    

    It's important that you only initialize the multiselect after you have set the attributes