Autocomplete should not trigger search on initial binding

Posted by: pascal.hanel on 31 January 2020, 9:26 am EST

    • Post Options:
    • Link

    Posted 31 January 2020, 9:26 am EST

    Hi all,

    I have quite a big reactive form that has some fields being prefilled from the backend. This is fine for all the input fields except the wj-auto-complete. I am using the itemsSourceFunction in order to get my records.

    Example:

              <wj-auto-complete
                formControlName="contact"
                [itemsSourceFunction]="getUserSuggestionList"
                [displayMemberPath]="'displayname'"
                [selectedValuePath]="'user_id'">
              </wj-auto-complete>
    

    I currently have 9 different autocompletes in my form, all of them being prefilled by myFormGroup.patchValue({bla: value}) with some data coming from the backend. Now the problem is, that for all of those 9 fields, the itemsSourceFunction is getting triggered, causing quite some unnecessary traffic to the backend. Is there any possibility to avoid fetching the data from the backend on the initial setting of the value (no user entry)?

    I’m using Angular v8 and wijmo v5.20192.624

    Thank you!

    Pascal

  • Posted 3 February 2020, 1:56 am EST

    Hi Pascal,

    This is expected behavior because when we set a value to the AutoComplete, it calls the itemsSourceFunction to get the values corresponding to the text.

    If you do not wish to call the itemsSourceFunction, you either set the itemsSourceFunction after calling the patchValue method or set a condition in the itemsSourceFunction that will check whether the query is empty and will return an empty data source. Please refer to the code snippet below:

    sourceFunc(query: string, max: number, callback: Function) {
    	if(query === "") {
    		callback(null);
    		return;
    	}
    ...
    }
    

    Regards,

    Ashwin

Need extra support?

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

Learn More

Forum Channels