Prevent Wijmo ComboBox to select the first item automatically

Posted by: muhammad.f.mehboob on 31 October 2019, 7:23 am EST

  • Posted 31 October 2019, 7:23 am EST

    Hi Team,

    I want to select the default value to blank on my combo box. I am usign Angular 4. Here is my code.

    <wj-combo-box #companyCombo class=“wj-combo-box”

    [itemsSource]=“dataMap_company”

    [displayMemberPath]=“‘company’”

    [selectedValuePath]=“‘companyId’”

    [isEditable]=“false”

    [placeholder]=“‘’”

    name=“cboCompany”

    [selectedIndex]=“‘selectedIndex’” (selectedIndexChanged)=“onCompanySelectedIndexChanged(companyCombo.selectedValue)”

    ngModel>

    export class GridCmp {

    @ViewChild(“cboCompany”) cboCompany;

    selectedIndex = ‘’;

    }

    I have tried the solution from this post (https://www.grapecity.com/forums/wijmo/how-to-prevent-combobox-to_1) but that didnt help me. Any solution how to do it?

    Thanks

  • Posted 31 October 2019, 2:42 pm EST

    Hi,

    You will need to set the isRequired property of the ComboBox to false and the value of selectedIndex to -1.

    <wj-combo-box [itemsSource]="source" displayMemberPath="country" [isRequired]="false" [(selectedIndex)]="selectedIndex"></wj-combo-box>
    
    this.selectedIndex = -1;
    

    You may refer to the sample below:

    https://stackblitz.com/edit/ckkyne-rnx7ra

    Regards,

    Ashwin

  • Posted 1 November 2019, 4:01 am EST

    Hi Ashwin,

    I tried your solution and it worked fine but I am using API to get data for my dropdown and its not working with it. Any reason?

    dataMap_company: any;

    this.m_dbService.getData(api)

    .subscribe

    (

    data =>

    {

    this.dataMap_company = data;

    },

    errorCode =>

    {

    console.log('errorCode: ’ + errorCode);

    }

    );

  • Posted 3 November 2019, 4:12 pm EST

    Hi,

    The issue may be regarding the result of the subscribe event. You may need to convert it to json format using the json() method:

    this.dataMap_company = data.json()
    

    Also, please make sure that the data contains an array.

    In case this does not solve your issue, could you please provide a screenshot of the error on the console, if an error is thrown. Also, could you provide a small sample replicating the issue?

    ~regards

  • Posted 11 November 2019, 3:20 am EST

    Hi Ashiwn,

    I got the following error message with data.json().

    TypeError: data.json is not a function

    Thanks

  • Posted 12 November 2019, 6:29 pm EST

    Hi,

    Could you please provide us with the information that I asked for earlier so that we can assist you further?

    ~regards

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels