truckingsim / Ajax-Bootstrap-Select

This uses the bootstrap-select plugin and extends it so that you can use a remote source to search.
MIT License
280 stars 97 forks source link

Add support for HTML attributs "data-xxx" on custom content #213

Open smartland007 opened 2 years ago

smartland007 commented 2 years ago

I would like to add the support for other HTML attributs. the defaults are too basic and do not allow to pass a lot of data from our data sources (ajax result).

  1. create a variable DATA_ATTRIBUTE_PATTERN at line 41
  2. add this variable in the global attributs allowed
  var ARIA_ATTRIBUTE_PATTERN = /^aria-[\w-]*$/i;
  var DATA_ATTRIBUTE_PATTERN = /^data-[\w-]*$/i;

  var DefaultWhitelist = {
    // Global attributes allowed on any supplied element below.
    '*': ['class', 'dir', 'id', 'lang', 'role', 'tabindex', 'style', ARIA_ATTRIBUTE_PATTERN, DATA_ATTRIBUTE_PATTERN],

The outcome would be the following for each line of result:

< a role="option" id="bs-select-1-1" tabindex="0" aria-setsize="4" aria-posinset="2"> < span class="text"> < div **data-name="test" data-ori="test" data-id="1604"** class="bbbb">Test TEST 1604</div > < /span> < /a>