I have a dropdown in a reactive form. eg :
<form [formGroup]='formGroupName'>
<ejs-dropdownlist [datasource]="javascriptOptionsObject" [fields]="{ text: 'label', value: 'code' }" formControlName="someFieldId"> </ejs-dropdownlist>
</form>
with a code behind like...
this.formGroupName = this.formBuilder.group({ someFieldId: '' })
this.javascriptOptionsObject : OptionsDto[] = { new OptionsDto { text : 'TextValue', code:'CodeValue' } .... }
Except, all fields are loaded from a http service using http calls. Often the foreign fields have inconsistent cases, eg: if the an Id for a gender field might have a value of 'Male' or 'male' or 'MALE'.
Is it possible to make the dropdown select a value from the datasource that does not match in case. I am reading values from a database which has inconsistent casing on the ids stored in fields, but I would prefer not to coerce all values and all codes in to uppercase.
Hmm, in my use case, the data for the data source and the data for the dropdown are coming form separate places. I've edited the stackblitz to better show my use case.
https://stackblitz.com/edit/angular-vnomal-bbbuev?file=app.component.ts
In the image above, ideally there would be a way to for the dropdown to select the gender for person 2, even though 'male' does not match 'Male'.
|
createdHandler(){
this.checkforValue(this.person)
}
checkforValue(person){
for(let data =0 ;data<this.dropdownOptions.length ;data++)
{
if(person.code.toString().toLowerCase() == this.dropdownOptions[data].code.toString().toLowerCase())
{
this.person = this.dropdownOptions[data];
break;
}
}
}
|
|
<ejs-dropdownlist id='games' #sample
[dataSource]='dropdownOptions'
[value]='person.code'
[fields]='fields'
[placeholder]='waterMark'
[popupHeight]='height'
(created)='createdHandler($event)'
>
</ejs-dropdownlist>
|