Dropdown select box for bootstrap 5

Overview

dselect

Dropdown select box for bootstrap 5

Demo

Features

  • Placeholder
  • Multiple
  • Search
  • Creatable
  • Clearable
  • Sizing
  • Validation

Installation

Install dselect with npm

npm install @jarstone/dselect

Install from cdn

<link rel="stylesheet" href="https://unpkg.com/@jarstone/dselect/dist/css/dselect.css">
<script src="https://unpkg.com/@jarstone/dselect/dist/js/dselect.js"></script>

Usage/Examples

<select class="form-select" id="dselect-example">
    <option value="chrome">Chrome</option>
    <option value="firefox">Firefox</option>
    <option value="safari">Safari</option>
    <option value="edge">Edge</option>
    <option value="opera">Opera</option>
    <option value="brave">Brave</option>
</select>
dselect(document.querySelector('#dselect-example'))

Options

const config = {
    search: false, // Toggle search feature. Default: false
    creatable: false, // Creatable selection. Default: false
    clearable: false, // Clearable selection. Default: false
    maxHeight: '360px', // Max height for showing scrollbar. Default: 360px
    size: '', // Can be "sm" or "lg". Default ''
}
dselect(document.querySelector('#dselect-example'), config)

options can also be set in "data-dselect-*" attribute

<select data-dselect-search="true" data-dselect-creatable="true" data-dselect-clearable="true" data-dselect-max-height="300px" data-dselect-size="sm" class="form-select" id="dselect-example">
...
</select>
Comments
  • Options with empty value are not visible

    Options with empty value are not visible

    Hi, thank you very much for this amazing JS! The problem I'm facing is when a SELECT has an empty OPTION (e.g. "Choose from the list...") where the value is an empty string, it doesn't appear in the choices. So it is impossible to remove a selection once 1 choice has been made. If the value is "0" it appears, but obviously the script receiving the form thinks there is something (0 is not ""). Is there a way to let appear the options with empty value ?

    THANK YOU!

    opened by EtienneDelepine 2
  • search in header texts

    search in header texts

    I had the requirement to not only search the texts of the options, but also the texts of the headers. If a header text matches, all options under that header are displayed as result.

    ⚠️The current solution i came up with has a problem in conjunction with creatable: If you need to add an option that has exactly the same name as an existing header, this will not be possible anymore (at least if the matching header contains options).

    opened by MaxEtMoritz 1
  • Options that are disabled are not visible.

    Options that are disabled are not visible.

    For eg.

    <option value="" disabled>Championship (England)</option>
    <option value="" disabled>No Teams in This League</option>
    

    I know disabled options should not be searchable, however, they should be viewable when you initially click the select box.

    opened by peterlaws 0
  • Modal form does not reset the dropdown selection upon close or submit

    Modal form does not reset the dropdown selection upon close or submit

    So basically, my dselect dropdown was based populate with another dropdown. the value for the second dropdown based on first dropdown. The thing is, when i used this dselect dropdown, the dropdown doesn't reset the form and selection of dropdown upon close the modal or submit.

    <div id="stock_adjustmentModal" class="modal fade">
        <div class="modal-dialog">
            <form method="post" id="stock_adjustment_form">
                <div class="modal-content">
                    <div class="modal-header">
                        <h4 class="modal-title" id="modal_title">Add Stock Adjustment</h4>
                        <button type="button" class="close" data-bs-dismiss="modal">&times;</button>
                    </div>
                    <div class="modal-body">
                        <span id="form_message"></span>
    
                        <div class="form-group">
                            <label>Date<span class="text-danger">*</span></label>     
                            <div class="input-group">
                                <div class="input-group-prepend">
                                    <span class="input-group-text" id="basic-addon1"><i class="fa fa-calendar"></i></span>
                                </div>
                                <input type="text" name="stock_date" id="stock_date" class="form-control" value="<?php echo $object->nowdt;?>" required/>
                            </div>     
                        </div>
                       
                        <div class="form-group">
                            <label>Category</label>
                            <select name="stock_category" id="stock_category" class="form-select" onchange="getId(this.value)" required>
                                <option value="0">Select Category</option>
                                <?php
                                $object->query = "SELECT * FROM tbl_category 
                                                  WHERE category_flag = 0 
                                                  ORDER BY category_id ASC";
    
                                $result = $object->get_result();
    
                                foreach($result as $row)
                                {
                                    echo '
                                    <option value="'.$row["category_id"].'">'.$row["category_name"].'</option>
                                    ';
                                }
                                ?>
                            </select>
                        </div>
    
                        <div class="form-group"> 
                           <label>Item <span class="text-danger">*</span></label>
                                <select class="form-select" name="stock_item" id="stock_item" required>
                                <option value="0">Select Item</option>
                                </select>
                         </div> 
                      
                        <div class="form-group">
                            <label>Stock Adjustment Quantity</label>
                                <input type="number" step=0.01 name="stock_adjustment_qty" id="stock_adjustment_qty" class="form-control" required/>
                        </div>
                        
                    </div>
                    <div class="modal-footer">
                        <input type="hidden" name="hidden_id" id="hidden_id" />
                        <input type="hidden" name="action" id="action" value="Add" />
                        <input type="submit" name="submit" id="submit_button" class="btn btn-success" value="Add" />
                        <button type="button" class="btn btn-default" data-bs-dismiss="modal">Close</button>
                    </div>
                </div>
            </form>
        </div>
    </div>
    
    <link rel="stylesheet" href="https://unpkg.com/@jarstone/dselect/dist/css/dselect.css">
    <link href="../vendor/bootstrap/bootstrap.min.css" rel="stylesheet">
    <script src="https://unpkg.com/@jarstone/dselect/dist/js/dselect.js"></script>
    
    <script>
    $(document).ready(function(){
    
        var dataTable = $('#tbl_stock_adjustment').DataTable({
            "processing" : true,
            "serverSide" : true,
            "order" : [],
            "ajax" : {
                url:"stock_adjustment_exec.php",
                type:"POST",
                data:{action:'fetch'}
            },
            "columnDefs":[
                {
                    "targets":'_all',
                    "orderable":false,
                },
            ],
        });
    
            $('#stock_date').datepicker({
                format: "yyyy-mm-dd",
                autoclose: true
            });
    
            $('#add_stock_adjustment').click(function(){
            
            $('#stock_adjustment_form')[0].reset();
    
            $('#stock_adjustment_form').parsley().reset();
    
            $('#modal_title').text('Add Stock Adjustment');
    
            $('#action').val('Add');
    
            $('#submit_button').val('Add');
    
            $('#stock_adjustmentModal').modal('show');
    
            $('#form_message').html('');
    
        }); 
    
        $('#stock_adjustment_form').parsley();
    
        $('#stock_adjustment_form').on('submit', function(event){
            event.preventDefault();
            if($('#stock_adjustment_form').parsley().isValid())
            {       
                $.ajax({
                    url:"stock_adjustment_exec.php",
                    method:"POST",
                    data:$(this).serialize(),
                    dataType:'json',
                    beforeSend:function()
                    {
                        $('#submit_button').attr('disabled', 'disabled');
                        $('#submit_button').val('wait...');
                    },
                    success:function(data)
                    {
                        $('#submit_button').attr('disabled', false);
                        if(data.error != '')
                        {
                            $('#form_message').html(data.error);
                            $('#submit_button').val('Add');
                        }
                        else
                        {
                            $('#stock_adjustmentModal').modal('hide');
                            $('#message').html(data.success);
                            dataTable.ajax.reload();
    
                            setTimeout(function(){
    
                                $('#message').html('');
    
                            }, 5000);
                        }
                    }
                })
            }
        });
    
    dselect(document.querySelector('#stock_category'),{
      search: true
    })
    
    dselect(document.querySelector('#stock_item'),{
      search: true
    })
     
    function getId(val){
            var item_id = +val;
            $.ajax({type:"POST",url: "stock_adjustment_exec.php",data:{item_id:item_id, action:'dditem'},success:function(data){
    
     $("#stock_item").html(data);
    
     dselect(document.querySelector('#stock_item'));
    
            }});} 
    </script>
    
    
    opened by neesaa00 0
  • Server Side data return not working

    Server Side data return not working

    The data coming from the server side is not loaded into the dropdown list when we add dselect (If I don't use the dselect add-on, the data reload works).

    The code HTML:

    <label for="states" class="control-label">Country</label>
    <select name="dc_countryID" id="country" class="form-select rounded-0 selectlist">
    <option value="0">Select</option>
    <option value="0">USA</option>
    <option value="0">Brazil</option>
    </select>
    
    <label for="states" class="control-label">State</label>
    <select name="dc_stateID" id="states" class="form-select rounded-0 selectlist">
    <option value="0">Select</option>
    </select>
    
    
    <label for="cities" class="control-label">City</label>
    <select name="dc_cityID" id="cities" class="form-select rounded-0 selectlist">
    <option value="0">Select</option>
    </select>
    

    Javascript code: (#states and #cities select tag ID)

    let selectList = document.querySelectorAll('.selectlist');
    if (selectList != null) {
      for (const sl of selectList) {
    	  dselect(sl, { search: true });
      }
    }
    
    $(document).ready(function(){
    
    $("#country").on("change",function() {
    var countryID = $(this).val();
    
    $.ajax({
      url: "action_ajax.php",
      type: "POST",
      cache: false,
      data: {countryID:countryID},
      success: function(data) {
      console.log(data);
      $("#states").html(data);
    },
      error: function (jqXHR, textStatus, errorThrown) { 
      errorFunction(); 
    }
    
    });
    });
    
    $("#states").on("change",function() {
    var statesID = $(this).val();
    
    $.ajax({
      url: "action_ajax.php",
      type: "POST",
      cache: false,
      data: {statesID:statesID},
      success: function(data) {
      console.log(data);
      $("#cities").html(data);
    },
      error: function (jqXHR, textStatus, errorThrown) { 
      errorFunction(); 
    }
    });
    });
    });
    
    opened by Fzoltan87 4
  • Updated to allow for options disable

    Updated to allow for options disable

    I noticed that when i put a disabled flag on an option during a foreach loop, it was not carrying the flag over to show that the option was disabled.

    So I went into the file and added in a disabledvalue check to check for the disabled flag, if it has the flag, add disableitem (with disabled='true') to the item, otherwise, ignore it.

    I figure this may help other people who need to disable certain items for a certain reason.

    opened by Rpgdudester 1
Releases(v1.0.4)
Grupprojekt för kurserna 'Javascript med Ramverk' och 'Agil Utveckling'

JavaScript-med-Ramverk-Laboration-3 Grupprojektet för kurserna Javascript med Ramverk och Agil Utveckling. Utvecklingsguide För information om hur utv

Svante Jonsson IT-Högskolan 3 May 18, 2022
Hemsida för personer i Sverige som kan och vill erbjuda boende till människor på flykt

Getting Started with Create React App This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: np

null 4 May 3, 2022
Kurs-repo för kursen Webbserver och Databaser

Webbserver och databaser This repository is meant for CME students to access exercises and codealongs that happen throughout the course. I hope you wi

null 14 Jan 3, 2023
Select creates a dropdown list of items with the selected item in closed view.

Native Base Select ?? This module includes a customizable multi-select and a single select component for Native Base. The package is both Android and

Blump Tech 3 Dec 25, 2022
A custom select dropdown. This is something that is not too difficult to make.

Custom-Dropdown-JS A custom select dropdown using basic JS fucntionality. This is something that is not too difficult to make. But it shows that you h

Devanshu Vashishtha 2 Mar 26, 2022
Converts select multiple elements into dropdown menus with checkboxes

jquery-multi-select Converts <select multiple> elements into dropdown menus with a checkbox for each <option>. The original <select> element is hidden

mySociety 22 Dec 8, 2022
a jquery searchable select dropdown

Select Search A simple jquery search on select options plugin for your website How To Use Just create an html structure that contains select tag e.g.

Juliver Galleto 1 Sep 25, 2020
Pure JavaScript (VanillaJS) dropdown menu, with multiple select and searching support

JS Select Pure JavaScript (VanillaJS) dropdown menu, with multiple select and searching support How to use To use the select plugins, two main file mu

Luigi Verolla 4 Mar 17, 2022
Custom alert box using javaScript and css. This plugin will provide the functionality to customize the default JavaScript alert box.

customAlertBoxPlugin Custom Alert Box Plugin Using JavaScript and CSS Author: Suraj Aswal Must Include CSS Code/Default Custom Alert Box Class: /* mus

Suraj Aswal 17 Sep 10, 2022
Extends Bootstrap Tooltips and Popovers by adding custom classes. Available for Bootstrap 3 and Bootstrap 4.

Bootstrap Tooltip Custom Class Extends Bootstrap Tooltips and Popovers by adding custom classes. Available for Bootstrap 3 and Bootstrap 4. Define you

Andrei Victor Bulearca 14 Feb 10, 2022
A simple Form Validation Utility for Bootstrap 3, Bootstrap 4, and Bootstrap 5 for Humans.

bootstrap-validate A simple Form Validation Utility for Bootstrap 3, Bootstrap 4, and Bootstrap 5 for Humans. ?? Support us with Developer Merchandise

null 138 Jan 2, 2023
A fast, vanilla JS customisable select box/text input plugin for modern browsers ⚡

choices A fast, vanilla, lightweight (~16kb gzipped ?? ), configurable select plugin for modern browsers. Similar to Select2 and Selectize but without

null 9 Aug 9, 2022
Selectize is the hybrid of a textbox and select box

Selectize is the hybrid of a textbox and select box. It's jQuery based, and it has autocomplete and native-feeling keyboard navigation; useful for tagging, contact lists, etc.

null 12.9k Jan 5, 2023
Multiple level dropdown works with Bootstrap 5, just like native support.

Bootstrap 5 Multiple Level Dropdown. For Bootstrap 4, please visit Bootstrap 4 Multiple Level Dropdown Using official HTML without adding extra CSS st

Dallas Lu 17 Dec 13, 2022
Build forms from JSON Schema. Easily template-able. Compatible with Bootstrap 3 out of the box.

JSON Form The JSON Form library is a JavaScript client-side library that takes a structured data model defined using JSON Schema as input and returns

null 2.6k Dec 28, 2022
Multiple Selection Combo Box using Bootstrap 3

MagicSuggest v2.1.6 Bug Fix (fix) Disabled arbitrary HTML and SCRIPT execution on input. MagicSuggest v2.1.5 (fix) prepend close button instead of app

null 1.3k Dec 22, 2022
Create Bootstrap 5 Modal Box using JavaScript with custom title, description, button labels and custom YES button callback

Dynamic BS5 Modal Box Create Bootstrap 5 Modal Box using JavaScript with custom title, description, button labels and custom YES button callback Insta

null 5 Oct 23, 2022
The jQuery plugin that brings select elements into the 21st century with intuitive multiselection, searching, and much more. Now with Bootstrap 5 support.

bootstrap-select The jQuery plugin that brings select elements into the 21st century with intuitive multiselection, searching, and much more. Now with

SnapAppointments 9.7k Dec 30, 2022
The jQuery plugin that brings select elements into the 21st century with intuitive multiselection, searching, and much more. Now with Bootstrap 5 support

bootstrap-select The jQuery plugin that brings select elements into the 21st century with intuitive multiselection, searching, and much more. Now with

SnapAppointments 9.7k Dec 30, 2022