abp icon indicating copy to clipboard operation
abp copied to clipboard

When using select2 there should be ability to specify an empty item

Open vnetonline opened this issue 2 years ago • 2 comments

When using Select2 dropdown in MVC there should be an option to specify an empty Option

    function initSelectUsers() {
        $selectUser.data('autocompleteApiUrl', '/api/app/issue-tracking-user/assignable-users');
        $selectUser.data('autocompleteDisplayProperty', 'name');
        $selectUser.data('autocompleteValueProperty', 'id');
        $selectUser.data('autocompleteItemsProperty', 'items');
        $selectUser.data('autocompleteFilterParamName', 'filter');

        abp.dom.initializers.initializeAutocompleteSelects($selectUser);
    }

I suggest having

 $selectUser.data('autocompleteEmptyDisplayProperty', 'Select User');
 $selectUser.data('autocompleteEmptyValueProperty', '00000000-0000-0000-0000-000000000000');

using the below code in ProcessResults:

  var mappedItems = _.map(data.items, function (item) {
      return { id: item.id, text: item.userName };
  });
  
  mappedItems.unshift({ id: '00000000-0000-0000-0000-000000000000', text: 'Select User' });
  return { results: mappedItems };

vnetonline avatar Aug 02 '22 02:08 vnetonline

Related to https://github.com/abpframework/abp/issues/12130

enisn avatar Aug 02 '22 06:08 enisn

Hi @vnetonline

Can you try to use data-allow-clear="true" attribute for your select. That option will work if you inititialize it according to Auto-Complete Select Documentation

This is an example:

    <select asp-for="Widget"
            class="auto-complete-select"
            data-allow-clear="true"
            data-autocomplete-api-url="/api/example/authors"
            data-autocomplete-display-property="name"
            data-autocomplete-value-property="code"
            data-autocomplete-items-property="items"
            data-autocomplete-filter-param-name="filter">
    </select>

enisn avatar Aug 02 '22 06:08 enisn

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Oct 01 '22 10:10 stale[bot]