How to prevent ComboBox to select the first item aotomatically?

Posted by: brachi-w on 14 September 2017, 2:41 am EST

    • Post Options:
    • Link

    Posted 14 September 2017, 2:41 am EST

    Hi.

    I’m using angular2 rc4.

    any way how can I prevent wijmo to auto select the first item?

    `

    <wj-combo-box #comboBox [itemsSource]=“validValues” [selectedItem]=“selectedValue” [itemFormatter]=“itemFormatter” [isEditable]=“false”

    (selectedIndexChanged)=“onSelectedIndexChanged(comboBox)” [required]=“false”

    class=“wj-date-input” dropDownCssClass="wj-date-dropdown>

    </wj-combo-box>

  • Posted 14 September 2017, 2:41 am EST

    Hi,

    You can initialize default value using selectedIndex, selectedItem or selectedValue properties of ComboBox control.

    Use one of the properties to set default value. Please have a look to following code snippet to display selected value using selectedIndex:

    HTML:

    <wj-combo-box [itemsSource]="data"
                  [selectedValuePath]="'id'"
                  [displayMemberPath]="'country'"
                  [selectedIndex]="selectedIndex">
    </wj-combo-box>
    export class AppCmp {
        protected dataSvc: DataSvc;
        data: wijmo.collections.CollectionView;   
        selectedIndex  = 3; // index of item to be select
        constructor( @Inject(DataSvc) dataSvc: DataSvc) {
            this.dataSvc = dataSvc;
            this.data = new wijmo.collections.CollectionView(this.dataSvc.getCmbBxData());
          
        }
       
    }
  • Posted 26 November 2018, 6:28 pm EST

    When you use Angular and use ngModel or formControlName.

    You should set [isRequired]=“false”

    As Html code below:

            <wj-combo-box #templateCtr
                  class="custom-wj-input-control xn-select"
                  placeholder="Please select"
                  [itemsSource]="templates"
                  [displayMemberPath]="'textValue'"
                  [selectedValuePath]="'idValue'"
                  [isEditable]="true"
                  [isRequired]="false"
                  [(ngModel)]="templateId"
                  (selectedIndexChanged)="changeTemplate()"
                  (gotFocus)="onFocusTemplate()">
            </wj-combo-box>
    

    When init you should reset the value of model to string empty “”

    setTimeout(() => {
                // Fixed: auto select first row in dropdownlist
                this.templateId = '';
            }, 500);
    
Need extra support?

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

Learn More

Forum Channels