invalid

The multiselect dropdown is inside a modal. so while opening the modal, instead of showing the selected values, its showing 1 selected or 2 selected in the dropdown. i want to show the selected values in the multi select dropdown.


<div class="modal fade app-c-modal--primary" [config]="{ backdrop: 'static' }" bsModal #editVehicleModal="bs-modal"
tabindex="-1" role="dialog">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<form [formGroup]="editVehicleForm">
<div class="modal-body pb-0">
<div class="user-details-row">
<div class="form-holder">
<div class="row">
<div class="col-md-6">
<div class="app-c-form-group-set form-group">
<div class="app-c-form-group multi-select">
<ejs-multiselect class="form-control app-l-form-control" id='plugType'
formControlName="plugTypeIds" [dataSource]='vehiclePlugTypeData'
[fields]='plugTypesFields' [mode]='mode' [(value)]="selectedPlugTypes">
ejs-multiselect>
div>
div>
div>
div>
div>
div>
div>
form>
div>
div>
div>

6 Replies

UD UdhayaKumar Duraisamy Syncfusion Team August 25, 2022 02:13 PM UTC

Hi Risvana,


We suggest you use the Box mode in MultiSelect component for your requirement. In Box mode, the selected items will be visualized in chip. Please refer the below documentation and sample for more details.


Documentation : https://ej2.syncfusion.com/angular/documentation/api/multi-select/#mode


Sample : https://stackblitz.com/edit/angular-hvgy6n?file=app.component.html,app.component.css,app.component.ts


Kindly try the above suggestion and let us know if this meets your requirement. if still face a problem, please share a video with your issue


If this post is helpful, please consider Accepting it as the solution so that other members can locate it more quickly.


Regards,

Udhaya Kumar D




UN Unknown replied to UdhayaKumar Duraisamy August 26, 2022 03:48 AM UTC

plug type ui.png

I need to use the Checkbox mode itself since this is the UI I'm following. Is there any other way to display those selected values in the dropdown instead of that '2 selected' text using the CheckBox mode.



UD UdhayaKumar Duraisamy Syncfusion Team August 26, 2022 05:59 AM UTC

Hi Risvana,


We have checked the reported requirement. We have prepared the sample with CheckBox mode and when you select the value, the selected value will be displayed as chips. Kindly refer to the below sample.


[app.component.html]

<ejs-multiselect

        id="multiselect-checkbox"

        #checkbox

        [dataSource]="countries"

        [placeholder]="checkWaterMark"

        [fields]="checkFields"

        [mode]="mode"

        [popupHeight]="popHeight"

        (change)="onChange($event)"

        [showDropDownIcon]="true"

        showSelectAll="true"

        (select)="onSelect($event)"

        (focus)="onFocus($event)"

        (created)="onCreate($event)"

        (selectedAll)="onSelectedAll($event)"

        (removed)="onRemoved($event)"

        [filterBarPlaceholder]="filterPlaceholder"

      ></ejs-multiselect>


[app.component.ts]

export class AppComponent {

    @ViewChild('checkbox')

    public mulObjMultiSelectComponent;

    public modestring;

    public filterPlaceholderstring;

    //define the data with category

    public countries: { [keystring]: Object }[] = [

        { Name: 'Australia'Code: 'AU' },

        { Name: 'Bermuda'Code: 'BM' },

        { Name: 'Canada'Code: 'CA' },

        { Name: 'Cameroon'Code: 'CM' },

        { Name: 'Denmark'Code: 'DK' },

        { Name: 'France'Code: 'FR' },

        { Name: 'Finland'Code: 'FI' },

        { Name: 'Germany'Code: 'DE' },

        { Name: 'Greenland'Code: 'GL' },

        { Name: 'Hong Kong'Code: 'HK' },

        { Name: 'India'Code: 'IN' },

        { Name: 'Italy'Code: 'IT' },

        { Name: 'Japan'Code: 'JP' },

        { Name: 'Mexico'Code: 'MX' },

        { Name: 'Norway'Code: 'NO' },

        { Name: 'Poland'Code: 'PL' },

        { Name: 'Switzerland'Code: 'CH' },

        { Name: 'United Kingdom'Code: 'GB' },

        { Name: 'United States'Code: 'US' }

    ];

    // map the groupBy field with category column

    public checkFieldsObject = { text: 'Name'value: 'Code' };

    // set the placeholder to the MultiSelect input

    public checkWaterMarkstring = 'Select countries';

    // set the MultiSelect popup height

    public popHeightstring = '350px';

    ngOnInit(): void {

        this.mode = 'CheckBox';

        this.filterPlaceholder = 'Search countries';

    }

    

    onChange(args) {

        if ((this.mulObj as any).viewWrapper) {

            (this.mulObj as any).viewWrapper.style.display = 'none';

        }

        (this.mulObj as any).chipCollectionWrapper.style.display = 'block';

        let inputPos = (this.mulObj as any).overAllWrapper.getBoundingClientRect()

        let popupPos = (this.mulObj as any).popupWrapper && (this.mulObj as any).popupWrapper.getBoundingClientRect();

        if (inputPos && popupPos && (inputPos.top + inputPos.height > popupPos.top)) {

            (this.mulObj as any).popupWrapper.style.top = (inputPos.top + inputPos.height) + 'px';

        }

      }

      onSelect(args) {

        (this.mulObj as any).addChip(args.itemData.Nameargs.itemData.Codeargs.e);

        var proxy = this;

        setTimeout(function () { proxy.onChange(args) }, 50)

      }

      onCreate(args) {

        (this.mulObj as any).chipCollectionWrapper = this.mulObj.createElement('span', {

          className: 'e-chips-collection',

          styles: 'display:none'

        });

        (this.mulObj as any).componentWrapper.appendChild((this.mulObj as any).chipCollectionWrapper); 

      }

      onFocus(args) {

        (this.mulObj as any).viewWrapper.style.display = 'none';

      }

      onSelectedAll(args) {

        (this.mulObj as any).hidePopup();

      }

      onRemoved(args) {

        var proxy = this;

        setTimeout(function () { proxy.onChange(args) }, 10)

      }

}



Sample : https://stackblitz.com/edit/angular-9endz3-nxk9vb?file=app.component.html,app.component.ts


Kindly try the above sample and let us know if this meets your requirement.


If this post is helpful, please consider Accepting it as the solution so that other members can locate it more quickly.


Regards,

Udhaya Kumar D




UN Unknown replied to UdhayaKumar Duraisamy August 29, 2022 12:15 PM UTC

Hi UdhayaKumar,

I am able to bind the data to the multi select, but now iam getting an extra comma at the end of the data. is there any way to remove that comma comma issue.png



UD UdhayaKumar Duraisamy Syncfusion Team August 30, 2022 05:30 PM UTC

Hi Risvana,


We are validating the requirement. We will update the further details in two business days (2nd September 2022).


Regards,

Udhaya Kumar D



UD UdhayaKumar Duraisamy Syncfusion Team September 1, 2022 03:05 PM UTC

Hi Risvana,


In the MultiSelect component, the selected values are appended correctly in the UI. If you want the selected items as a string we suggest you use instances of the component. Please refer to the below sample for more details.


document.getElementById('multiselect-checkbox').ej2_instances[0].text


Sample : https://stackblitz.com/edit/angular-9endz3-yzqht5?file=app.component.html,app.component.ts


Kindly try the above suggestion and let us know if this meets your requirement. If we misunderstood the requirement, we request you to provide additional details about the requirement as mentioned below. This will help us validate the requirement further and provide you with a better solution.


  1. Exact Requirement details.
  2. Requirement use case scenario.


If this post is helpful, please consider Accepting it as the solution so that other members can locate it more quickly.


Regards,

Udhaya Kumar D



Loader.
Up arrow icon