wjAutoComplete can't get selectedValue working when itemsource is remote

Posted by: shinya.koizumi on 19 June 2018, 5:42 am EST

  • Posted 19 June 2018, 5:42 am EST

    I have problem selecting a particular item in the auto complete. It seems like it works when the object list is in the client side but always select the first one when the object list is the server side. The following are the source code for each components. Let me know if I am doing anything wrong. I am using wijmo 5.20181.462 and install it using “npm install wijmo”

    app.component ==============

    // src/app/app.component.ts
    import { Component } from '@angular/core';
    import { DataService} from "../services/data.service";
    // import Wijmo components
    import {WjAutoComplete, WjInputNumber} from 'wijmo/wijmo.angular2.input';
    @Component({
      selector: 'app-root',
      templateUrl: './app.component.html',
      styleUrls: ['./app.component.css'],
      providers:[DataService]
    })
    export class AppComponent {
      title = 'Wijmo Starter App';
      itemlist: any[];
      itemList2: any[];
      constructor(private dataService: DataService){
    
      	
    
      	this.dataService.getData()
        .subscribe((data: any) =>{
            this.itemlist = data;
        });
    
        this.itemList2=[
      		{"gdpm": 57825, "country": "Luxembourg", "gdpcap": 102708, "id": 1, "popk": 563}, 
      		{"gdpm": 664005, "country": "Switzerland", "gdpcap": 80602, "id": 2, "popk": 8238}
      	];
      }
    	  
    }
    

    app.component.html

    <!-- The content below is only a placeholder and can be replaced. -->
    <div style="text-align:center">
      <h1>
        Welcome to {{ title }}!
      </h1>
      
    </div>
    <h2>Here are some Wijmo controls to help you start:</h2>
    <wj-auto-complete [itemsSource]="itemlist"
                           [selectedValuePath]="'country'"
                           [displayMemberPath]="'country'"
                           [selectedValue]="'Switzerland'">
    </wj-auto-complete>
    
    <wj-auto-complete [itemsSource]="itemList2"
                           [selectedValuePath]="'country'"
                           [displayMemberPath]="'country'"
                           [selectedValue]="'Switzerland'">
    </wj-auto-complete>
    
    

    data.service.ts

    
    import { Injectable } from '@angular/core';
    import { HttpClient,HttpHandler } from '@angular/common/http';
    
    @Injectable()
    export class DataService {
      constructor(private http: HttpClient) { }
      getData(){
      	return this.http.get("http://www.json-generator.com/api/json/get/cfFvxGrIrS");
      }
    }
    
    
  • Posted 19 June 2018, 5:15 pm EST

    Hi,

    The behavior observed by you is expected. Since, as the Data assigned to the Control the Control selectedValue gets set to the first item. Hence, if you would like to set selectedValue for Control, then assign selectedValue to the Control once items are loaded for Control. For this, the itemsSourceChanged event may be used.

    Please refer to the following code snippet for the same:

    <wj-auto-complete [itemsSource]="itemlist" #ac
    [selectedValuePath]="'country'"
    [displayMemberPath]="'country'"
    (initialized)="init(ac)">
    
    /*init method  */
    init(ac){
    	ac.itemsSourceChanged.addHandler(()=>{
    		ac.selectedValue="Switzerland";
    	});
    }
    

    Hope it helps!

    ~Manish

  • Posted 20 June 2018, 5:03 am EST

    Thanks for clarifying.

    So is this work around and planning to fix near the future? I know selectedValue was working fine for remote calls before ( a few years back) now I need to explicitly call to set.

  • Posted 20 June 2018, 10:34 pm EST

    Hi,

    This behavior is by design. Could you please share build version which used to be work fine. So that we can verify at our end.

    The above-suggested workaround is a recommended fix for this issue.

    ~Manish

Need extra support?

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

Learn More

Forum Channels