ionic-selectable icon indicating copy to clipboard operation
ionic-selectable copied to clipboard

how to preselect values

Open bayarder opened this issue 3 years ago • 1 comments

I have an array of values with true or false

question.values = [ { "key": "xx", "value": "yy", "isChecked": false }, { "key": "xx", "value": "yy", "isChecked": true }, { "key": "xx", "value": "yy", "isChecked": false } ]

How to preselect value with true in html code

image

bayarder avatar Jul 01 '22 09:07 bayarder

Hi @bayarder,

If you are using FormControl :

<ionic-selectable
	[canSearch]="true"
	formControlName="region"
	[items]="regions"
	itemValueField="code"
	itemTextField="name">
</ionic-selectable>

in your ts file you have just to set the FormControl inside a setTimeout like :

// ...code
public regions: Array<any> = [{code: "1", name: "Region 1"}, {code: "2", name: "Region 2"}];

// ...code
setTimeout(() => {
    this.region.setValue({code: "2", name: "Region 2"});
});

You'll get the ion-selectable label updated.

Good luck.

w-mazed avatar Jul 11 '22 10:07 w-mazed